Mysql从多列中获取重复数字

时间:2017-04-22 19:00:35

标签: mysql

我有一个类似于以下SqlFiddle http://sqlfiddle.com/#!9/f30a65/1/0

的数据库

我需要获取该组,但问题是数据在多列上......

例如预期的结果:

VALUE - COUNT或Group By

13 - 2

11 - 1

感谢所有人

1 个答案:

答案 0 :(得分:1)

如果您想要分组,可以使用

组合所有列
SELECT value, count(value) as count FROM (
    SELECT C1 as value FROM TABLE1
    UNION ALL
    SELECT C2 as value FROM TABLE1
    UNION ALL
    SELECT C3 as value FROM TABLE1
    UNION ALL
    SELECT C4 as value FROM TABLE1
    UNION ALL
    SELECT C5 as value FROM TABLE1
    UNION ALL
    SELECT C6 as value FROM TABLE1
) all_col GROUP BY value