Search for largest SQL vendors

0

I need a SQL code that shows me the best sellers but in the result show me which of the stores this official belongs to.

I can do the research to know which are the best sellers but I do not know to select from which store it is. Here is my code below:

select distinct co_operador, count(*) as qtidade_lib
from [dbo].[pistb002_liberacao_beneficio]
group by co_operador
order by "qtidade_lib" desc
    
asked by anonymous 12.12.2015 / 23:47

1 answer

0

Assuming there is a store table named TbLojas and it is related to this table that you used in the example through the LojaID field.

The Instruction would be + - like this:

select distinct B.co_operador, L.NomeLoja, count(B.*) as qtidade_lib
from [dbo].[pistb002_liberacao_beneficio] B
Inner Join TbLojas L
ON B.LojaID = L.LojaID
group by B.co_operador, L.NomeLoja
order by "qtidade_lib" desc

If you can give more information about where the store table is and how it is related to this profit table it is easier ...

    
13.12.2015 / 03:31