日期:2014-05-17 浏览次数:20617 次
;with cte(总数,月份) as
(
select 5,1
union all select 5,1
union all select 2,1
union all select 3,1
union all select 53,2
union all select 10,2
union all select 2,2
union all select 3,3
union all select 5,4
union all select 6,5
union all select 10,5
union all select 20,6
union all select 20,6
union all select 53,7
union all select 53,7
union all select 53,7
union all select 53,7
union all select 53,7
union all select 53,8
union all select 53,8
)
select 月份,SUM(总数) as 总数
from cte
group by 月份
/*
月份 总数
1 15
2 65
3 3
4 5
5 16
6 40
7 265
8 106
*/
create table ys(总数 int,月份 int)
insert into ys
select 5,1
union all select 5,1
union all select 2,1
union all select 3,1
union all select 53,2
union all select 10,2
union all select 2,2