SELECT条件不一样

时间:2014-05-17 15:19:17

标签: sql oracle

enter image description here

如果扩展价格不等于小计,如何显示发票?

以下查询无法运行,此处不允许使用错误组功能

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;

1 个答案:

答案 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);