日期:2014-05-18 浏览次数:20945 次
if exists(select *from sysobjects where name ='Stable' and xtype='u') drop table Stable
create table Stable ([ID] varchar(20),[NAME] VARCHAR(30),[COUNT] int)
insert into Stable
select '100' , '张三' ,100 union all
select '101' , '张三' ,101 union all
select '103' , '李四' ,300 union all
select '104' , '王五' ,400 union all
select '105' , '赵六' ,700
SELECT [NAME],SUM([COUNT]) TCount FROM Stable GROUP BY [NAME] ORDER BY [NAME]
/*
NAME TCount
------------------------------ -----------
李四 300
王五 400
张三 201
赵六 700
(所影响的行数为 4 行)
*/