UPDATE
This is the query that seems to have it.
SELECT
E.ID,
P.Packages,
I.Items
FROM EXPEDITION E
LEFT JOIN (
SELECT DISTINCT E.ID, COUNT(P.ID) AS "Packages" FROM EXPEDITION E
LEFT JOIN PACKAGE P
ON E.ID = P.EXPEDITION_ID
GROUP BY E.ID
) P
ON E.ID = P.ID
LEFT JOIN (
SELECT DISTINCT P.ID as "PackageID", COUNT(I.ID) AS "Items" FROM PACKAGE P
JOIN ITEM I
ON P.ID = I.EXPEDIITONPACKAGE_ID
GROUP BY P.ID
) I
ON P.ID = I.PackageId
GROUP BY
E.ID,
P.Packages,
I.Items
ORDER BY
E.ID
It has two inner queries, that count the IDs separately, and they are joined in the main query to show the results.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…