select colx,
sum(case when col=bm1 then 1 else 0 end) as bm1
sum(case when col=bm2 then 1 else 0 end) as bm2
from table
group by colX
sum(case when col=bm1 then 1 else 0 end) as bm1
sum(case when col=bm2 then 1 else 0 end) as bm2
from table
group by colX
解决方案 »
- 创建视图有重复列
- sql server 2005 单表查询 不加order by时记录顺序
- 在ODBC中添加数据源(SQL Server),但是为什么会出现“ODBC Text 安装”对话框,而不出现“创建到 SQL Server 的新数据源”对话框,谢谢!
- BEGIN END 问题,各位大哥大姐帮帮忙
- 请教各位一个关于改写binary数据类型的问题!!
- sql server 临时文件 位置更改 导致的问题
- 我从其他地方copy了一个mssql的数据库,但不知怎样引入自己的sql-server中?
- 关于timer组见的interval属性中的最小单位
- 如何插入如下的结果集???
- sql查询语句求助
- 各位前辈,我在数据库中有一个字段io-time是datetime类型的,我如何查询数据库中某一时间段内的数据?
- 高手进来!!!看看这个,谁能帮我解决如下存储程序问题?分数全给他?
sum(case when col=bm1 then 1 else 0 end) as bm1
sum(case when col=bm2 then 1 else 0 end) as bm2
from table
group by colX,col
see again, different recorderset different result column nums
Just Like Test Our E Level!!UP!
SUM(CASE WHEN bm='bm2' THEN bb ELSE NULL) as bm2
FROM(SELECT sp,bm,SUM(s1) as bb
from tab
group by sp,bm
) tmp
GROUP BY sp--想不出有其它情況(不止bm1,bm2)的方法。
this problem from
http://expert.csdn.net/Expert/topic/1229/1229844.xml?temp=9.800357E-02
(case when (select count(*) from table where col='bm1')>0 then (sum(case when (select count(*) from table where col='bm2')>0 then ((case when col=bm1 then 1 else 0 end) as bm1) end))
sum(case when col=bm2 then 1 else 0 end) as bm2
from table
group by colX
(case
when (select count(*) from table where col='bm1')>0 then
(sum(case when col=bm1 then 1 else 0 end) as bm1)
end)(case
when (select count(*) from table where col='bm2')>0 then
(sum(case when col=bm2 then 1 else 0 end) as bm2)
end)
from table
group by colX