我有这个查询
SELECT username FROM paymentValue
我可以将paymentValue
加上像
SELECT username, SUM(paymentValue) WHERE username = 'john'
但是如何为所有用户名选择总和以获得返回: 约翰,146 结婚,3456 安娜,2043年
答案 0 :(得分:3)
使用'group by'子句
select username, sum(paymentvalue) as sumofpayments from thetable
group by username
答案 1 :(得分:1)
SELECT username, SUM(paymentValue)
FROM TableName
GROUP BY username
与另一张桌子加入
SELECT username, SUM(paymentValue)
FROM TableName INNER JOIN SecondTable
ON TableName.RefrencingColumn = SecondTable.RefrencingColumn
WHERE username = 'john'
GROUP BY username
答案 2 :(得分:0)
select username,
sum(paymentValue) as Payments
from paymentValue
group by username