Det är nu ännu enklare:PostgreSQL 9.4 introducerade mode()
funktion:
select mode() within group (order by food_id)
from munch
group by country
returnerar (som user2247323s exempel):
country | mode
--------------
GB | 3
US | 1
Se dokumentation här:https://wiki.postgresql.org/wiki/Aggregate_Mode
https://www.postgresql.org/docs/current/static/functions-aggregate.html#FUNCTIONS-ORDEREDSET-TABLE