仅当价格不是0,00时才依靠SQL

时间:2012-04-16 10:08:50

标签: sql group-by

我有这样的表:

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

我该怎么做?

提前谢谢你。

3 个答案:

答案 0 :(得分:6)

假设Price是文本字段:

select  zone
,       count(case when Price <> '0,00' then 1 end) as total
from    YourTable
group by
        zone

如果价格是数字字段,请将Price <> '0,00'替换为Price > 0

答案 1 :(得分:3)

这也有效:

SELECT Zone, COUNT(NULLIF(Price,0)) AS Total FROM Table1 GROUP BY Zone

答案 2 :(得分:0)

SELECT ZONE, COUNT(*) FROM yourtable WHERE PRICE<> '0.00' GROUP BY ZONE 

应该这样做