一月份公司外bug数应该是1create table #tb (Id int,月份 int,bug数 int,Bug分类 nvarchar(10))
insert into #tbselect 1, 1, 1, '公司外' union all
select 2, 2, 1, '公司外' union all
select 3, 2, 1, '公司外' union all
select 4, 3, 1, '公司外' union all
select 5, 1, 1, '公司内' union all
select 6, 3, 1, '公司内' union all
select 7, 4, 1, '公司外'select * from #tbselect 月份,SUM(bug数) as bug总数,SUM(case bug分类 when '公司外' then 1 else 0 end) as 司外Bug总数
from #tb group by 月份/*
月份 bug总数 司外Bug总数
----------- ----------- -----------
1 2 1
2 2 2
3 2 1
4 1 1(4 行受影响)
*/
insert into #tbselect 1, 1, 1, '公司外' union all
select 2, 2, 1, '公司外' union all
select 3, 2, 1, '公司外' union all
select 4, 3, 1, '公司外' union all
select 5, 1, 1, '公司内' union all
select 6, 3, 1, '公司内' union all
select 7, 4, 1, '公司外'select * from #tbselect 月份,SUM(bug数) as bug总数,SUM(case bug分类 when '公司外' then 1 else 0 end) as 司外Bug总数
from #tb group by 月份/*
月份 bug总数 司外Bug总数
----------- ----------- -----------
1 2 1
2 2 2
3 2 1
4 1 1(4 行受影响)
*/
from #tb group by 月份
if语句这个地方应该不是1或者0 应该是bug数或者0
if语句这个地方应该不是1或者0 应该是bug数或者0 嗯,是的,回复太仓促了,修改如下:select 月份,SUM(bug数) as bug总数,SUM(iif(bug分类='公司外',bug数,0)) as 公司外Bug总数
from tb group by 月份
if语句这个地方应该不是1或者0 应该是bug数或者0 嗯,是的,回复太仓促了,修改如下:select 月份,SUM(bug数) as bug总数,SUM(iif(bug分类='公司外',bug数,0)) as 公司外Bug总数
from tb group by 月份
高手,再帮我解决另一个问题吧http://bbs.csdn.net/topics/390694809
if语句这个地方应该不是1或者0 应该是bug数或者0 嗯,是的,回复太仓促了,修改如下:select 月份,SUM(bug数) as bug总数,SUM(iif(bug分类='公司外',bug数,0)) as 公司外Bug总数
from tb group by 月份
高手,再帮我解决另一个问题吧http://bbs.csdn.net/topics/390694809哥辛苦写了场,你一分也不给呀…