如何分类求和

帮别人做个小系统的时候遇到的问题,因为经验不足,困扰了好些天:
在统计的时候,在用户这一字段有好多用户,而用户每天都交易产生交易金额。
我想实现的是统计出每个用户的交易金额的总和
即:由以下
用户 金额 交易编号
A 1 1
A 2 2
A 3 3
B 1 4
B 2 5
B 3 6
C 2 7
C 2 8

要统计出
用户 金额
A 6
B 3
C 4

恳请各位高手指教

---------------------------------------------------------------

select 用户,sum(金额) from table group by 用户;
---------------------------------------------------------------

SELECT SUM(金额) AS COUNT
FROM 表
GROUP BY 用户
---------------------------------------------------------------

select (select count(A) from table where 用户="A"),(select count(B) from table where 用户="B"),select count(C) from table where 用户="C"
---------------------------------------------------------------

select sum(a.c) from (select top 5 * from test where a='a') a
---------------------------------------------------------------

select 用户,sum(金额) as s from table group by 用户

Published At
Categories with Web编程
Tagged with
comments powered by Disqus