SQL查询以针对单个ID找出总和 [英] Sql query to find out sum against individual id

查看:46
本文介绍了SQL查询以针对单个ID找出总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这样的表:

名称:table_money

name: table_money

我需要一个SQL查询,该查询将产生以下结果,其中包含每个ID的金额.

I need a sql query that produces the following result containing sum of money for each id.

我该如何找出一个身份证件的总金额?

How can I find out the total money of an individual id?

什么是SQL查询?

推荐答案

要获取每个ID的总和,您需要按 id 列将结果分组并应用 SUM 将函数聚合到 money 列.

To get the sum for each ID you need to group the results by the id column and apply the SUM aggregate function to the money column.

SELECT id, SUM(money) 
FROM table_money
GROUP BY id

您可以在此处阅读有关SQL结果分组的更多信息:

You can read more about grouping of SQL results here:

  • Group by two columns and display grand total in every row
  • Having Sums, Averages, and Other Grouped Data by Oracle Magazine
  • GROUP BY (Transact-SQL) on MSDN

这篇关于SQL查询以针对单个ID找出总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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