目前我有 9 列
Brand, ID, M, T, W, Th, Fri, Sat, Sun
abc, 1, 2, 4, 6, 3, 7, 1, 5
我想找出以下哪组的个体数最多。 月/周/周/日、周五、周六/周日。例如,在上表中,将选择星期五,因为它的计数最高。
最佳答案
假设值之间没有联系,您可以使用 greatest
和 case
表达式来完成此操作。如果存在平局,则将返回 case
表达式中遇到的第一个值(平局天数中的值)。
select case greatest(M, T, W, Th, Fri, Sat, Sun)
when M then 'Monday'
when T then 'Tuesday'
when W then 'Wednesday'
when Th then 'Thursday'
when Fri then 'Friday'
when Sat then 'Saturday'
when Sun then 'Sunday'
end
from tbl
关于MySQL从一组列中查找最大计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46409456/