总共重复行值 [英] Sum duplicate row values

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

问题描述



表名(客户)

我正在尝试总结第二行的重复值的值, >

 价值年总额
1 30 30
3 10 10
4 15 15
4 25 25

我最好终于有:

 价值年总额
1 30 30
3 10 10
4 40 40
pre>

我尝试使用 SELECT DISTINCT GROUP BY 摆脱重复的行,也不需要在下面的代码中加入。无论这两个命令无济于事。这是我的代码:

  SELECT DISTINCT 
value,
years,
SUM(customer 。年)AS总
从客户
INNER JOIN语言
ON customer.expert = language.l_id
GROUP BY
专家,
年;

但是产生第一张表的副本,任何输入欢迎。谢谢!!!

解决方案

  SELECT 
value,
SUM (年)AS年,
SUM(总计)AS总额
从客户
GROUP BY值;

你想要年的总和和总和的总和, 分组价值。


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

Table name (Customers)

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

I would ideally like to finally have:

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

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天全站免登陆