Sum duplicate row values

I am trying to summarize the values ​​of strings, two of which have duplicate values, table below:

Table Name (Clients)

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

Ideally, I would like to finally:

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

I tried to use SELECT DISTINCTand GROUP BYto get rid of the duplicate line, the connection in the code below is also not required. Despite the fact that both teams to no avail. Here is also my code:

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 this creates a copy of the first table, any input is welcome. Thanks!!!

+4
source share
2 answers
SELECT
   value,
   SUM(years) AS years,
   SUM(total) AS total
FROM customers
GROUP BY value;

You want the sum of years and the sum of the total, per - to be grouped by - value.

+16
source
SELECT 
  value,
  years,
  SUM(customer.years) AS total FROM (SELECT DISTINCT 
  value,
  years,
  customer.years AS total 
FROM customer 
INNER JOIN language 
  ON customer.expert=language.l_id ) as TABLECUS
GROUP BY 
  expert, 
  years;
0

All Articles