日期:2014-05-18 浏览次数:20558 次
create table x(col varchar(10)) insert into x values('true') insert into x values('true') insert into x values('true') insert into x values('true') insert into x values('false') insert into x values('false') go select col , count(*) cnt from x group by col --drop table col /* col cnt ---------- ----------- false 2 true 4 (所影响的行数为 2 行) */
------解决方案--------------------
只有两种的话,不用group也行:
select col='true', cnt=count(1) from tb where col='true' union all select col='false', cnt=count(1) from tb where col='false'
------解决方案--------------------
select col, [count] = case col when 'true' then count(col) else count(col) end
from X
group by col
------解决方案--------------------
select col,count(1) from x group by col