如何在不同用户的SQL Server中获取列的总和? [英] How to get sum of columns in SQL Server for different users?

查看:50
本文介绍了如何在不同用户的SQL Server中获取列的总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从PaymentMaster表获得一个名为PaidAmount的列的总和,该表具有UserId字段,因为一个用户可能有很多记录,现在我想要每个用户的Total PaidAmount总和。那么有人能帮帮我吗?





我试过这样



I want to get sum of a column called "PaidAmount" from PaymentMaster table, which has UserId field, In that one user may have many records, Now I want the sum of Total PaidAmount of each user. So Can anyone help me please?


I tried like this

select Sum(PaidAmount) from PaymentMaster

select Sum(PaidAmount) from PaymentMaster where UserId=@UserId





但是在第一次查询中,我得到所有用户的总付费金额,在第二次查询中我要通过每个userId。







感谢@ dv @ nce:P

推荐答案

尝试:

Try:
SELECT UserID, SUM(PaidAmount) AS Total FROM PaymentMaster GROUP BY UserId


这篇关于如何在不同用户的SQL Server中获取列的总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆