假设有一张A表 table A
id name flag
---------------------------
1 'a' true
2 'b' false
3 'c' true
4 'd' true
现在想用一条sql语句实现统计 flag=false的数量和 flag=true的数量期望结构如下:select count(id) as y,count(id) as n from A ..... 在此先谢啦....
id name flag
---------------------------
1 'a' true
2 'b' false
3 'c' true
4 'd' true
现在想用一条sql语句实现统计 flag=false的数量和 flag=true的数量期望结构如下:select count(id) as y,count(id) as n from A ..... 在此先谢啦....
select count(id) as y, flag from A group by flag
http://topic.csdn.net/u/20090812/14/290b75ad-b187-41b9-89b9-b8fc160c8609.html
select
sum(case when flag='true' then 1 else 0 end) TRUE个数,
sum(case when flag='false' then 1 else 0 end) FALSE个数
from A;