对重复的行值求和 [英] Sum duplicate row values

查看:33
本文介绍了对重复的行值求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对其中两个具有重复值的行的值求和,我拥有的表格如下:

I'm trying to sum the values of rows two of which have duplicate values, the table I have is below:

表名(客户)

value   years   total
1           30    30
3           10    10
4           15    15
4           25    25

我希望最终拥有:

value  years   total
1      30      30
3      10      10
4      40      40

我尝试使用 SELECT DISTINCTGROUP BY 来删除重复的行,下面代码中的连接也不是必需的.无论如何,这两个命令都无济于事.这也是我的代码:

I've tried using SELECT DISTINCT and GROUP BY to get rid of the duplicate row, also the join in the code below isn't necessary. Regardless both commands come to no avail. Here's my code too:

SELECT DISTINCT 
  value,
  years,
  SUM(customer.years) AS total 
FROM customer 
INNER JOIN language 
  ON customer.expert=language.l_id 
GROUP BY 
  expert, 
  years;

但这会产生第一个表的副本,欢迎任何输入.谢谢!!!

But that produces a copy of the first table, any input welcome. Thanks!!!

推荐答案

SELECT
   value,
   SUM(years) AS years,
   SUM(total) AS total
FROM customers
GROUP BY value;

您需要年份的总和和总数的总和,每 —分组 —价值.

You want the sum of the years and the sum of the total, per — grouped by — value.

这篇关于对重复的行值求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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