我有以下查询:
SELECT sum(p.price) as "totalPurchase", sum(s.price) as "totalSale", sum(er.price) as
"totalRet", v.name as "vendor"
FROM "Esns" e
JOIN "EsnsPurchaseOrderItems" ep on ep."EsnId" = e.id
JOIN "PurchaseOrderItems" p on ep."PurchaseOrderItemId"= p.id
JOIN "PurchaseOrders" po on p."PurchaseOrderId" = po.id
JOIN "Vendors" v on po."VendorId" = v.id
LEFT OUTER JOIN "EsnsSalesOrderItems" es on es."EsnId" = e.id
LEFT OUTER JOIN "SalesOrderItems" s on es."SalesOrderItemId" = s.id
LEFT OUTER JOIN "EsnsRmas" er on er."EsnId" = e.id
GROUP BY v.id
但是,我还想计算由上述连接组织的所有 e.id 以及字段 e."inStock" = true。