日期:2014-05-17 浏览次数:20961 次
create table #t([id] int,[trueName] varchar(4),[userName] varchar(3),[score] int)
insert #t
select 1,'张三','zs',80 union all
select 2,'张三','zs1',100 union all
select 3,'张三','zs2',90
go
select [trueName],MAX([userName]),SUM([score])
FROM #t
GROUP BY [trueName]
if object_id('tb') is not null drop table tb
go
create table tb([id] int,[trueName] varchar(4),[userName] varchar(3),[score] int)
insert tb
select 1,'张三','zs',80 union all
select 2,'张三','zs1',100 union all
select 3,'张三','zs2',90
select trueName,max(username) as username,sum(score) as score
from tb
GROUP BY truename
/*
trueName username score
张三 zs2 270
*/