Sum of values according to value of another column

Asked

Viewed 25 times

-1

I have two doubts that are difficult for me but that maybe I can be simple for you.

inserir a descrição da imagem aqui

I wondered how I could make a sum of the amount according to the units that in this case would be the units Maracanã, Botafogo and São Cristóvão.

And the other question would be how could I make a sum of the amount according to each date, for example, on the day 21/02/2021 had a total of 1132.

OBS: I wanted to know how to do in a query only in each of the situations to be able to perform a Plot.

Thank you!

1 answer

1


"make a sum of the quantity according to the units"

To do this, use the quantity sum function, and group by unit:

SELECT unidade,
       SUM(quantidade)
  FROM nome-da-tabela
 GROUP BY unidade

"make a sum of the quantity according to each date"

Same concept, but grouped by date:

SELECT data,
       SUM(quantidade)
  FROM nome-da-tabela
 GROUP BY data

Browser other questions tagged

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