如果扩展价格不等于小计,如何显示发票?
以下查询无法运行,此处不允许使用错误组功能
SELECT a.INVOICENUMBER,SUM(a.EXTENDEDPRICE),SUM(a.SUBTOTAL)
FROM CUSTOMERORDERHISTORYVIEW a
WHERE EXISTS
(SELECT a1.INVOICENUMBER FROM CUSTOMERORDERHISTORYVIEW a1 WHERE
a.INVOICENUMBER=a1.INVOICENUMBER AND SUM(a1.EXTENDEDPRICE) <> SUM(a1.SUBTOTAL))
GROUP BY a.INVOICENUMBER;
答案 0 :(得分:2)
您正在寻找having
子句:
SELECT a.INVOICENUMBER, SUM(a.EXTENDEDPRICE), SUM(a.SUBTOTAL)
FROM CUSTOMERORDERHISTORYVIEW a
GROUP BY a.INVOICENUMBER;
HAVING SUM(a.EXTENDEDPRICE) <> SUM(a.SUBTOTAL);