查询获取显示数量的次数

时间:2018-01-24 02:28:15

标签: mysql sql

我需要帮助!

我有这个文件表(这里是简化版):

       +----+-----+----+
Columns| v1 | v2  | v3 |
       +----+-----+----+
       | 1  | 5   | 11 |
       | 2  | 7   | 5  |
       | 10 | 11  | 18 |
       | 5  | 7   | 10 |
       +----+-----+----+

我想知道显示数字1,2,5,7,10,11和18的次数,与输入的列无关

1 个答案:

答案 0 :(得分:1)

您可以使用union all“取消”数据,然后使用聚合:

select v, count(*)
from ((select v1 as v from t) union all
      (select v2 as v from t) union all
      (select v3 as v from t) union all
     ) t
group by v;