日期:2014-05-18 浏览次数:20409 次
--表 a --id time1 time2 --1 200 300 --1 300 400 --2 100 100 --2 300 500 --求查询结果为 --id sum(time1) sum (time2) --1 500 700 --2 400 600 declare @a table(id int,time1 int,time2 int) insert into @a values (1 ,200 ,300), (1, 300 ,400), (2, 100 ,100), (2 ,300 ,500 ) select id ,(select SUM(time1) from @a where a.id=id)as 'sum(time1)', (select SUM(time2) from @a where a.id=id) as 'sum (time2)' from @a a group by id id sum(time1) sum (time2) ----------- ----------- ----------- 1 500 700 2 400 600 (2 行受影响)