27,579
社区成员
发帖
与我相关
我的任务
分享
-- =============================================
-- Author: T.O.P
-- Create date: 2009/11/21
-- Version: SQL SERVER 2005
-- =============================================
declare @tb2 table([a] int,[b] varchar(4))
insert @tb2
select 1,'张三' union all
select 2,'张三' union all
select 3,'张三' union all
select 4,'张三' union all
select 3,'王二' union all
select 2,'王二' union all
select 12,'王二' union all
select 8,'李四' union all
select 1,'李四'
select [b],sum(a) as a
from @tb2
group by [b]
--测试结果:
/*
b a
---- -----------
李四 9
王二 17
张三 10
*/