I have a schema , where u have a Travel table, People table and a ClientTravel table that references both the Travel table and People Table. I want to do the query that gives me the Client(s) that made the most travels in a year.
I've done a subquery that gives me the count of times a ClientId appeared in the ClientTravel Table like so:
SELECT cv.idpessoa , count(cv.idpessoa) as noviagens
FROM viagem v , clienteviagem cv ,pessoa p
WHERE EXTRACT(YEAR FROM v.dtviagem)=2021 and v.idsistema = cv.viagem and p.id =cv.idpessoa
GROUP BY cv.idpessoa
i Would like to do another query that uses the result of the previous one where it only gives me the PeopleId with the max Count.
I've managed to do a table that looks like this:
| idpessoa | count |
|---|---|
| 1234 | 10 |
| 5431 | 1 |
| 1242 | 3 |
| 8567 | 5 |
And now i want to retrieve a table like this :
| idpessoa |
|---|
| 1234 |
Find the idpessoa that has the max value of count. Thanks for your time