SQL, count in multiple columns then group by

后端 未结 2 1818
礼貌的吻别
礼貌的吻别 2021-01-12 16:52

I am trying to count in multiple columns then group by for a total sum where the same data appears in any column

Source data table:

P1  P2  P3
-----------
a         


        
2条回答
  •  醉酒成梦
    2021-01-12 17:37

    You can use a union query

    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
    

提交回复
热议问题