下面的查询就像一个美女。现在我正在尝试选择PRODUCT.*
导致错误代码的
42Y36: (Column reference '<value>' is invalid. For a SELECT list with a GROUP BY, the list may only contain grouping columns and valid aggregate expressions.)
接下来我尝试同时设置和SELECT
导致GROUP BY
错误代码PRODUCT.*
42X01: (Syntax error: <error>.)
一个普通的语法错误。好的,似乎不允许在GROUP BY
. 所以我的问题是(不需要子查询),“如何在使用定义的子句时选择整个对象HAVING
?”
SELECT PRODUCT.ID
FROM PRODUCT
LEFT JOIN DELIVERYROW ON DELIVERYROW.PRODUCT_ID = PRODUCT.ID
LEFT JOIN DISPATCHROW ON DISPATCHROW.PRODUCT_ID = PRODUCT.ID
WHERE PRODUCT.DTYPE = 'PRODUCT'
GROUP BY PRODUCT.ID
HAVING (
COALESCE(SUM(DELIVERYROW.AMOUNT),0)
-
COALESCE(SUM(DISPATCHROW.AMOUNT),0)
) > 0