Mysql 查询获取数字的显示次数
我需要帮助 我有此文件表(此处为简化版):Mysql 查询获取数字的显示次数,mysql,sql,Mysql,Sql,我需要帮助 我有此文件表(此处为简化版): 我想知道数字1、2、5、7、10、11和18显示了多少次,与输入的列无关您可以使用union all来“unpivot”数据,然后使用聚合: 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
我想知道数字1、2、5、7、10、11和18显示了多少次,与输入的列无关您可以使用
union all
来“unpivot”数据,然后使用聚合:
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;
太快了。。太快了。这种问题是糟糕设计的症状
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;