我在下面有这个连接查询。我有一个问题。shipUnits 列出现错误。它只计算总项目。问题是我正在计算两组对象,除了发货字段之外,它们具有所有共同点。
SELECT count(*) as "units", (select count("EsnsVmas".*) from "EsnsVmas" where
"EsnsVmas"."shipped" = false AND "EsnsVmas"."VmaId" = 2 AND "EsnsVmas"."approved" =
true) as "shippedUnits", "Vmas".*, "Vendors"."name" as "name", "EsnsVmas".id as
"OrderItemId", "PurchaseOrderItems"."price", "Grades"."name" as "vendorGrade",
"Items"."name" as "model", "Items".id as "ItemId", "Grades".id as "GradeId"
FROM "Vmas"
JOIN "EsnsVmas" on ("EsnsVmas"."VmaId" = "Vmas".id)
JOIN "Esns" on ("EsnsVmas"."EsnId" = "Esns".id)
JOIN "PurchaseOrderItems" on ("Esns"."PurchaseOrderItemId" =
"PurchaseOrderItems".id)
JOIN "Items" on ("PurchaseOrderItems"."ItemId" = "Items".id)
JOIN "Grades" on ("PurchaseOrderItems"."GradeId" = "Grades".id)
JOIN "Vendors" on ("Vmas"."VendorId" = "Vendors".id)
WHERE "Vmas".id =2 AND "EsnsVmas"."approved" = true
GROUP BY "Vmas".id, "PurchaseOrderItems".id, "Grades".id, "Items".id, "Vendors".id, "EsnsVmas".id ;