How do I return my records grouped by NULL and NOT NULL?

前端 未结 14 930
说谎
说谎 2021-01-30 16:24

I have a table that has a processed_timestamp column -- if a record has been processed then that field contains the datetime it was processed, otherwise it is null.

14条回答
  •  北海茫月
    2021-01-30 16:37

    Another MySQL method is to use the CASE operator, which can be generalised to more alternatives than IF():

    SELECT CASE WHEN processed_timestamp IS NULL THEN 'NULL' 
                ELSE 'NOT NULL' END AS a,
           COUNT(*) AS n 
           FROM logs 
           GROUP BY a
    

提交回复
热议问题