Basically a great JOIN
fix everything:
select v.PrimeiroNome as "Nome do Vendedor", r.Nome as "Região"
from Vendedores v
inner join Cidades c on c.Id = v.IdCidade
inner join Estados e on e.Id = c.IdEstado
inner join Regionais r on r.Id = e.IdRegional;
To count:
select tabela.Nome as "Região", count(*) from
(select v.PrimeiroNome as "Nome do Vendedor", r.Nome -- as "Região"
from Vendedores v
inner join Cidades c on c.Id = v.IdCidade
inner join Estados e on e.Id = c.IdEstado
inner join Regionais r on r.Id = e.IdRegional) tabela
-- group by "Região"; -- Isto aqui deu erro no Browser.
group by tabela.Nome
I did, but it didn’t work out. My problem is in making the related Seller count (Table 1) filtered by Region (Table 4) and then grouping everything (group by).
– Mauro Alves
I updated the answer.
– Leonel Sanches da Silva
It worked perfectly in the query program. I already marked as correct, but in the Browser it was error.
Each GROUP BY expression must contain at least one column that is not an outer reference
Would you know what it means? Anyway thank you so much.– Mauro Alves
Strange to have given it. I updated again.
– Leonel Sanches da Silva