MySQL Group by - Get columns with zero count

后端 未结 3 1939
一生所求
一生所求 2021-01-14 03:29

I tried decrying other answers, no luck, hence asking.

I have one table and few more similar to this for other year Here is the table structure

--         


        
3条回答
  •  长发绾君心
    2021-01-14 04:05

    A fairly straight forward way is to get all distinct statuses and LEFT JOIN with the table to get the counts;

    SELECT a.status, COUNT(b.status) cnt
    FROM (SELECT DISTINCT status FROM Table1) a
    LEFT JOIN Table1 b
      ON a.status = b.status
     AND b.`Company name`='Microsoft'
    GROUP BY a.status
    

    An SQLfiddle to test with.

提交回复
热议问题