我试图在多列中计数,然后按总和将相同数据显示在任何列中
Source data table: P1 P2 P3 ----------- a b a a a b c a b b b a
我希望它显示如下内容:
Desired query output: Total ------------- a | 6 b | 5 c | 1
您可以使用联合查询
SELECT x.f1,Count(x.f1) FROM (SELECT p1 As F1 FROM table UNION ALL SELECT p2 As F1 FROM table UNION ALL SELECT p3 As F1 FROM table) x GROUP BY x.f1