Get most common value for each value of another column in SQL

前端 未结 9 1582
生来不讨喜
生来不讨喜 2020-11-30 02:29

I have a table like this:

 Column  | Type | Modifiers 
---------+------+-----------
 country | text | 
 food_id | int  | 
 eaten   | date | 
<
9条回答
  •  萌比男神i
    2020-11-30 02:56

    try this:

    Select Country, Food_id
    From Munch T1
    Where Food_id= 
        (Select Food_id
         from Munch T2
         where T1.Country= T2.Country
         group by Food_id
         order by count(Food_id) desc
          limit 1)
    group by Country, Food_id
    

提交回复
热议问题