select [名称],sum([金钱]) as [金钱] from tb group by [名称]
---测试数据--- if object_id('[tb]') is not null drop table [tb] go create table [tb]([名称] varchar(4),[金钱] int) insert [tb] select '张三',1 union all select '张三',2 union all select '李四',2 union all select '李四',3
---查询--- select 名称,sum(金钱)金钱 from tb group by 名称 ---结果--- 名称 金钱 ---- ----------- 李四 5 张三 3(2 行受影响)
from tb
group by [名称]
from tb
group by [名称]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([名称] varchar(4),[金钱] int)
insert [tb]
select '张三',1 union all
select '张三',2 union all
select '李四',2 union all
select '李四',3
---查询---
select 名称,sum(金钱)金钱 from tb group by 名称
---结果---
名称 金钱
---- -----------
李四 5
张三 3(2 行受影响)
from tb
group by 名称