我想获取 mySQL 表中所有列的最常见值。
[id] [UserID] [UserID2]
1 johnnietheblack marywhite
2 johnnietheblack marywhite
3 dannyrottenegg dannyrottenegg
4 marywhite marywhite
5 marywhite johnnietheblack
6 johnnietheblack marywhite
这是我想要的输出:
[id] [UserID] [Count]
1 johnnietheblack 4
2 dannyrottenegg 2
3 marywhite 6
我可以使用以下内容来获取一列的常用值。但是我怎样才能得到所有列的共同值呢?
SELECT COUNT(*) AS `Rows`, UserID
FROM table-name
GROUP BY UserID
ORDER BY `Rows` DESC