日期:2014-05-17 浏览次数:20721 次
if OBJECT_ID('tempdb..#temp', 'u') is not null drop table #temp;
go
create table #temp( [表头] varchar(100), [ID] int, [VAL] int, [NAME] varchar(100));
insert #temp
select '数据','1','56','jack' union ALL
SELECT '数据','1','10','jack' UNION ALL
SELECT '数据','1','10','jack' UNION ALL
select '数据','2','101','mary' union all
select '数据','3','34','john' union all
select '数据','4','99','jerry'
--SQL:
;WITH cte AS
(
select id, name, val=SUM(val) from #temp GROUP BY id, name