2012-05-21 149 views

回答

14

像這樣的東西可能:

SELECT SUM(CASE WHEN x > 0 THEN 1 ELSE 0 END) as GreatherThanZero 
    , SUM(CASE WHEN x = 0 THEN 1 ELSE 0 END) as EqualZero 
FROM table 
WHERE x >= 0 
+0

燁它的工作.. – X10nD

+0

謝謝,這是有益的。 – RichardW11

0

好吧,如果我理解正確你的問題,這樣的事情應該工作:

SELECT 
    COUNT(Field) 
FROM 
    Table 
WHERE 
    Field >= 0 
1

是。

SELECT SUM(CASE WHEN column > 0 THEN column ELSE 0 END CASE), SUM(CASE WHEN column < 0 THEN column ELSE 0 END CASE) FROM mytable 
5

是的。

SELECT COUNT(*) FROM Table WHERE Field > 0 
UNION SELECT COUNT(*) FROM Table WHERE Field = 0 
相關問題