我有事件表,现在我想使用SQL在列中显示最频繁的元素这是事件表。id | selectedcountries0 | Tanzania1 | Tanzania2 | Tanzania3 | Kenya4 | Uganda5 | Uganda6 | Kenya7 | Uganda8 | Tanzania8 | Poland9 | Poland10 | Tanzania  更新    例如,对于此表,它应该返回坦桑尼亚,因为它是  最常见的值:这是我的解决方案SELECT selectedcountries, COUNT( 'selectedcountries' ) AS 'country'FROM EVENTSGROUP BY 'selectedcountries'ORDER BY 'country' DESC不幸的是,我得到以下selectedcountries country 73我需要做什么才能得到我想要的东西? 最佳答案 这在统计中称为模式。如果需要单个值,可以使用group by和limit:select selectedcountriesfrom eventsgroup by selectedcountriesorder by count(*) desclimit 1;Here是db 小提琴。有联系时,这不会返回多个值。获取联系的所有值的一种方法是聚合的两个层次:select group_concat(selectedcountries)from (select selectedcountries, count(*) as cnt from events group by selectedcountries ) tgroup by cntorder by cnt desclimit 1;关于mysql - 使用sql显示数据库中的数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57375509/
10-10 16:21