我有这样的表:
ID Price ZONE
-- ----- ----
1 0,00 A
2 6,00 A
3 8,56 A
4 0,00 B
我想展示:
ZONE TOTAL
---- -----
A 2
B 0
我怎样才能做到这一点?
提前谢谢你。
假设Price
是一个文本字段:
select zone
, count(case when Price <> '0,00' then 1 end) as total
from YourTable
group by
zone
如果 price 是数字字段,请替换Price <> '0,00'
为Price > 0
。
这也有效:
SELECT Zone, COUNT(NULLIF(Price,0)) AS Total FROM Table1 GROUP BY Zone
SELECT ZONE, COUNT(*) FROM yourtable WHERE PRICE<> '0.00' GROUP BY ZONE
应该这样做