2017-05-06 60 views
0

我想让文本回到最多次。获取不同MySQL记录的重现

例1:

Column1 Column2 Column3 Column4 Column5 
Red  Red  Red  White Blank 

结果的询问:

Red 

例2:

Colum1 Colum2 Colum3 Colum4 Colum5 
White White Red  Yellow Blank 

结果的询问:

White 

回答

0

我最近遇到类似这个问题的东西。希望这可以帮助。

select col 
from 
(select col1 as col from tab1 
union all 
select col2 as col from tab1 
union all 
select col3 as col from tab1 
union all 
select col4 as col from tab1 
union all 
select col5 as col from tab1) as new_table 
group by col order by count(*) desc limit 1; 
+0

完美,我工作! –