序号 物料 数量 重量
1 A 3 5
1 A 5 6
1 B 2 6
2 C 1 9
2 D 4 2
2 D 6 3
2 C 8 5
我想得到的结果是:
序号 物料 数量 重量
1 A 8 11
1 B 2 6
合计 10 17
2 C 9 14
2 D 10 5
合计 19 19
相同序号中的,物料相同的数据进行汇总,但是重量按照物料的汇总
GOUPING WITH ROLLUP
SQL code:
----------------------------------------------------------------
-- Author :fredrickhu(小F,向高手学习)
-- Date :2009-09-03 19:50:10
-- Verstion:
-- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86)
-- Nov 24 2008 13:01:59
-- Copyright (c) 1988-2005 Microsoft Corporation
-- Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 3)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([姓名] varchar(4),[学期] int,[语文] int,[数学] int,[英语] int,[政治] int)
insert [tb]
select '张三',1,70,60,80,30 union all
select '张三',2,80,90,75,40 union all
select '张三',3,50,70,85,60 union all
select '李四',1,66,80,