日期:2014-05-18  浏览次数:20491 次

多项同时统计的问题?
select   count(字段)   as   js1,count(字段)   as   js2   中
count(字段)   as   js1和count(字段)   as   js2   统计条件不同,这样的sql语句怎么写?

------解决方案--------------------
--try

select
sum(case when 字段= '值1 ' then 1 else 0 end) as js1,
sum(case when 字段= '值2 ' then 1 else 0 end) as js2,
from tbName

------解决方案--------------------
select B.名称, count(*) sj,
sum(case when 字段= '值1 ' then 1 else 0 end) as js1,
sum(case when 字段= '值2 ' then 1 else 0 end) as js2
from A inner join B on A.代码=B.代码 and B.类别= '水果 '
group by B.名称