Det er nu endnu enklere:PostgreSQL 9.4 introducerede mode()
funktion:
select mode() within group (order by food_id)
from munch
group by country
returnerer (som bruger2247323s eksempel):
country | mode
--------------
GB | 3
US | 1
Se dokumentation her:https://wiki.postgresql.org/wiki/Aggregate_Mode
https://www.postgresql.org/docs/current/static/functions-aggregate.html#FUNCTIONS-ORDEREDSET-TABLE