Procedure sql server, return the total value of an id

1

I have a bank of products sold forming by id, name and value. I would like to do a procedure that would return total of each product that was sold. Algem knows how to do it?

That the result is

Mouse = 60
CPU = 1500
Keyboard = 100

    
asked by anonymous 14.10.2015 / 18:35

1 answer

3

Explanation

You can use the SUM() aggregation function to sum the values and group the results by the name of the products with the GROUP BY clause.

Query

SELECT 
    nome_produto [Nome do Produto],
    SUM(valor_produto) [Valor Total]
FROM
   produtos_vendidos
GROUP BY
   nome_produto
    
14.10.2015 / 19:56