日期:2014-05-19  浏览次数:20490 次

如何实现count(TickState=2)这种样式?
select   count(TickState)   as   UseTotal,count(TickState=2)   as   WasteTotal
from   toll_list
就是一个字段有3种取值,取出每种取值的记录数.
但是不能用该字段group.因为还要取其它值.
谢谢!

------解决方案--------------------
select count(TickState) as UseTotal,sum(case when TickState=2 then 1 else 0 end) as WasteTotal
from toll_list
------解决方案--------------------
select UseTotal = sum(case TickState when 1 then 1 else 0 end),
WasteTotal = sum(case TickState when 2 then 1 else 0 end)
from toll_list