I have the following question. Consider that I have the following sales data:
Two states: São Paulo (Atibaia, São Paulo and Campinas) and Paraná (Londrina, Curitiba, Cascavel).
| cidade | estado | vendas |
|-----------|--------|--------|
| Cascavel | PR | 10 |
| Curitiba | PR | 8 |
| Londrina | PR | 3 |
| Campinas | SP | 3 |
| São Paulo | SP | 5 |
| Atibaia | SP | 3 |
I need to bring the cities of their respective states that have the largest number of sales.
I made this command: to count in the city there brings the sum, but I need to separate the cities now. in that case he would have to bring São Paulo and Cascavel.
select
count(d_clientes.cidade_nome), f_pedidos.cliente_sk, d_clientes.cliente_sk, d_clientes.cidade_nome, d_clientes.estado_nome, d_clientes.estado_sigla
from
f_pedidos
inner join d_clientes on f_pedidos.cliente_sk = d_clientes.cliente_sk
group by d_clientes.cidade_nome