一个分类汇总

create table testone(
 name1 varchar(10), name2 varchar(10),num1 int,num2 int
)--见表
insert into testone
select 'aa','AA',1,1 union all
select 'dd','DD',2,2 union all
select 'aa','A',3,3 union all
select 'dd','DD',4,4

--插入数据

  汇总的条件是:
  Num1汇总时按Name1来分类
  Num2汇总时按Name2来分类

select id=identity(int,1,1), name1,sum(num1)as num1 into one from testone group by name1
select id=identity(int,1,1), name2,sum(num2)as num2 into two from testone group by name2
select name1,num1,name2,num2 from two full join one on one.id=two.id

--分类汇总

猜你喜欢

转载自blog.csdn.net/jianguangguo/article/details/4158427
今日推荐