简体   繁体   English

SQL查询-选择用户名并汇总其行

[英]SQL query - select usernames and sum their row

I have this query 我有这个查询

SELECT username FROM paymentValue

I can sum paymentValue for username like 我可以总结paymentValue像用户名

SELECT username, SUM(paymentValue) WHERE username = 'john'

But how to select sums for all usernames to get return like: john, 146 marry, 3456 anna, 2043 但是如何为所有用户名选择总和以获取回报,例如:约翰,146结婚,3456安娜,2043

use the 'group by' clause 使用“ group by”子句

select username, sum(paymentvalue) as sumofpayments from thetable
group by username
SELECT username, SUM(paymentValue) 
FROM TableName
GROUP BY username

to JOIN with another table 与另一个表联接

SELECT username, SUM(paymentValue) 
FROM TableName INNER JOIN SecondTable
ON TableName.RefrencingColumn = SecondTable.RefrencingColumn  
WHERE username = 'john'
GROUP BY username
select username,
       sum(paymentValue) as Payments
from paymentValue
group by username

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM