I have a problem with a query in an Oracle database in a table with 3 columns:
ID_Loja | Canal | Valor_Venda
There is the possibility of having more than one sale per store and I want to know which channel was assigned to the store based on the amount of sales each store had as shown below. In this case, I want the query to just return the row containing the "A" channel since in this case 5 sales vs. 4 sales occurred for the same store with a different rating.
ID_Loja: 1
Canal: A
Count(Valor_Venda): 5
ID_Loja: 1
Canal: B
Count(Valor_Venda): 4
So far, I have done only the query which brings the amount of sales per store / channel, but I was not able to bring just the combination that has more sales per store / channel only.
SELECT ID_Loja, Canal, COUNT(Valor_Venda)
FROM Vendas
GROUP BY ID_loja, Canal