I Have 3 tables like that:
EXPEDITION (ID, CreateDate, Status);
PACKAGE (ID, EXPEDITION_ID)
ITEM (ID, EXPEDIITONPACKAGE_ID);
I need to know, for each expedition, the quantity of packages and the quantity of items.
I Have 3 tables like that:
EXPEDITION (ID, CreateDate, Status);
PACKAGE (ID, EXPEDITION_ID)
ITEM (ID, EXPEDIITONPACKAGE_ID);
I need to know, for each expedition, the quantity of packages and the quantity of items.
UPDATE
This is the query that seems to have it.
It has two inner queries, that count the IDs separately, and they are joined in the main query to show the results.
Try this. Not tested yet...but it should work.. ;With c1 as ( Select e.expid, count(e.expid) as qtyPck From packages p inner join Expeditions e on p.expid = e.expid Group by e.expid ), C2 as ( Select i.pakId, count(i.pakId) as qtyItems From items i inner join packages p On i.pakId = p.pakId Group by i.pakid ) Select e.expId, p.qtyPck, I.qtyItems From expeditions e Join packages p on p.expId = e.expId Join items i on i.pakId = p.pakId;