Cliente_ID | Nome | Cidade | Estado |
---|---|---|---|
101 | João Silva | São Paulo | SP |
102 | Maria Souza | Rio de Janeiro | RJ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT c.Nome, SUM(v.Valor) AS Total_Gasto | |
FROM Vendas v | |
JOIN Cliente c ON v.Cliente_ID = c.Cliente_ID | |
GROUP BY c.Nome; |
ID_Venda | Data_ID | Cliente_ID | Produto_ID | Quantidade | Valor |
---|---|---|---|---|---|
1 | 20240201 | 101 | 501 | 2 | 50.00 |
2 | 20240201 | 102 | 502 | 1 | 30.00 |
id | categoria | valor |
---|---|---|
1 | Eletrônicos | 1000 |
2 | Eletrônicos | 1500 |
3 | Móveis | 800 |
4 | Móveis | 1200 |
5 | Eletrônicos | 500 |
id | categoria | valor | ranking |
---|---|---|---|
2 | Eletrônicos | 1500 | 1 |
1 | Eletrônicos | 1000 | 2 |
5 | Eletrônicos | 500 | 3 |
4 | Móveis | 1200 | 1 |
3 | Móveis | 800 | 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
id, | |
categoria, | |
valor, | |
RANK() OVER (PARTITION BY categoria ORDER BY valor DESC) AS ranking | |
FROM vendas; |
id | categoria | valor | total_produtos |
---|---|---|---|
1 | Eletrônicos | 1000 | 3 |
2 | Eletrônicos | 1500 | 3 |
5 | Eletrônicos | 500 | 3 |
3 | Móveis | 800 | 2 |
4 | Móveis | 1200 | 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
id, | |
categoria, | |
valor, | |
COUNT(*) OVER (PARTITION BY categoria) AS total_produtos | |
FROM vendas; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
id, | |
categoria, | |
valor, | |
AVG(valor) OVER (PARTITION BY categoria) AS media_categoria | |
FROM vendas; |
id | categoria | valor | media_categoria |
---|---|---|---|
1 | Eletrônicos | 1000 | 1000 |
2 | Eletrônicos | 1500 | 1000 |
5 | Eletrônicos | 500 | 1000 |
3 | Móveis | 800 | 1000 |
4 | Móveis | 1200 | 1000 |