我有下表
如何编写SQL语句以了解至少有1000次采购具有相同ServiceType,PaymentType和GST值的购买数量?
我知道我需要使用计数聚合,我认为查询应该像这样开始
由于
答案 0 :(得分:3)
select count(*)
from PURCHASE
group by ServiceType, PaymentType, GST
having count(*) >= 1000
答案 1 :(得分:3)
我认为你需要数而不是总和。或者,如果您需要总金额,请将金额加总。
SELECT COUNT(PurchaseNo)
FROM PURCHASE
GROUP BY ServiceType, PaymentType, GST
HAVING COUNT(PurchaseNo) >= 1000
答案 2 :(得分:0)
你可以这样做:
select COUNT(*),ServiceType, PaymentType, GST
FROM PURCHASE
having count(*) > 1000
group by ServiceType, PaymentType, GST;