Status
1
1
1
2
2
3
Status
1
1
2
2
2
2
3
3
如何获取以下结果表
Status Count
1 5
2 6
3 3
帮助我构建SQL查询以获取结果表中的计数。
答案 0 :(得分:1)
Try this
SELECT Status, COUNT(*) FROM
(SELECT a.Status FROM TableA AS a
UNION ALL
SELECT b.Status FROM TableB AS b) UN
GROUP BY Status
答案 1 :(得分:0)
SELECT STATUS, COUNT(*) FROM
(SELECT STATUS FROM TABLE1
UNION ALL
SELECT STATUS FROM TABLE2) un
GROUP BY STATUS