Procedure sql server, return the total value of an id

Asked

Viewed 101 times

1

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

Let the result follow

inserir a descrição da imagem aqui

Mouse = 60
CPU = 1500
Keyboard = 100

1 answer

3


Explanation

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

Query

SELECT 
    nome_produto [Nome do Produto],
    SUM(valor_produto) [Valor Total]
FROM
   produtos_vendidos
GROUP BY
   nome_produto

Browser other questions tagged

You are not signed in. Login or sign up in order to post.