;with ETA(ref,count1) as
(select Int1, count(Int1) from [yourtable] group by Int1
union all
select Int2, count(Int2) from [yourtable] group by Int2)
select count1, count(count1) from ETA group by count1
SELECT count(c.student) as cnt, c.inte
FROM
(
SELECT `int1` as inte,student FROM course
union all
SELECT `int2` as inte,student FROM course
) c
GROUP BY c.inte
ORDER BY c.inte
2条答案
按热度按时间uajslkp61#
首先,我将2结果连接到一个临时表中,并按临时表进行计数。
waxmsbnn2#
您可以查询这两列中的数据,然后使用
UNION ALL
将它们放在一起,最后使用GROUP BY
统计数据DB Fiddle Demo
测试结果
Cnt|inte
3|数据库
4|DS
4|网络
5|操作系统