首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

多项同时统计的有关问题

2012-02-24 
多项同时统计的问题?selectcount(字段)asjs1,count(字段)asjs2中count(字段)asjs1和count(字段)asjs2统计

多项同时统计的问题?
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.名称

热点排行