multiple sums in the same table

7

I have the following problem, I have 1 table in mysql where I have the information of people who have a debt from a clothing store for several years, what I want is a query that gives me the name of the person and that adds up your debt.

Example of the table and its data:

nombre |  año | monto
Pepe   | 2011 | 100.00
Pepe   | 2012 | 300.00
Pepe   | 2016 | 900.00
Maria  | 2011 | 100.00
Maria  | 2012 | 530.00

Result:

Pepe  | 2011 | 13000.00
Maria  | 2012 | 630.00

The year does not matter I just want the sum.

    
asked by Abraxas 03.06.2016 в 22:32
source

1 answer

2

You can do it with the SUM function . Consider that SUM is a grouping function, so you need a statement GROUP BY that indicates the fields that will be grouped to make the addition.

Here is the example of how it would look.

SELECT nombre, SUM(monto)
FROM tuTabla
GROUP BY nombre
ORDER BY nombre
    
answered by 03.06.2016 / 22:44
source