0
Hello, everybody!
I have a table of customers with Grupo Economico code and CNPJ, each economic group has more than one record, and I cross-checked with my Billing and Address table, so far so good.
I wanted to take the CNPJ address of higher billing and have as final result only Code Economic Group and Address, without showing the CNPJ and Billing, but I can’t.
After crossing tried the code below, but the result is wrong, the address is not CNPJ higher billing:
Select CodGrupo, NomeGrupo, First(CNPJ), Max(Fat), Cidade, UF
From tbl_EndFat
Group By CodGrupo, NomeGrupo, Cidade, UF
OrderBy max(fat)
Edit: My goal is for the query to return the highest billing CNPJ address for each economic group.
Any suggestions?
Why the "
First(CNPJ)
"? The goal is just to return the record of higher billing?– João Martins
No, I expressed myself badly, the goal is to return the CNPJ address of higher turnover for each Economic Group.
– Alan Teixeira