Search larger SQL sellers

Asked

Viewed 68 times

0

I need an SQL code that shows me the best sellers but in the result show me which store this employee belongs to.

I can do the research to find out which are the best sellers but I don’t know how to select which store it is from. Below is my code:

select distinct co_operador, count(*) as qtidade_lib
from [dbo].[pistb002_liberacao_beneficio]
group by co_operador
order by "qtidade_lib" desc
  • 3

    And where is the store recorded? Another table? In the same?

1 answer

0

Suppose there is a store table called Tblojas and it is related to this table that you used in the example via the Lojaid field.

Instruction would look 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 benefit table it is easier...

Browser other questions tagged

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