您好我滥用了聚合:以后查询的sum()错误。这有什么不对。
> Select storeid, supplierid, ordernumber, inwardnumber, returnid,
> taxinvoiceno, ordervalue, sum(CASHPAID) as 'CASHPAID', balancedue,
> paidamt, paiddate, sum(ADJUSTMENT) as
> ADJUSTMENT,ordervalue+sum(ADJUSTMENT) as total from
> supplierpaymentstabledb where storeid = 10008 and total!=CASHPAID
> group by inwardnumber
答案 0 :(得分:3)
作为一种良好实践,您应该将所有非聚合列放在group by
子句中。然后,聚合列的条件应该是having
子句,而不是where
子句:
Select storeid, supplierid, ordernumber, inwardnumber, returnid,
taxinvoiceno, ordervalue, sum(CASHPAID) as CASHPAID, balancedue,
paidamt, paiddate, sum(ADJUSTMENT) as ADJUSTMENT,
ordervalue + sum(ADJUSTMENT) as total
from supplierpaymentstabledb
where storeid = 10008
group by storeid, supplierid, ordernumber, inwardnumber, returnid,
taxinvoiceno, ordervalue, balancedue,
paidamt, paiddate
having total <> CASHPAID;