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

前端 未结 14 933
说谎
说谎 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:47

    SQL Server (starting with 2012):

    SELECT IIF(ISDATE(processed_timestamp) = 0, 'NULL', 'NON NULL'), COUNT(*)
    FROM MyTable
    GROUP BY ISDATE(processed_timestamp);
    
    0 讨论(0)
  • 2021-01-30 16:48

    In T-SQL (MS SQL Server), this works:

    SELECT
      CASE WHEN Field IS NULL THEN 'NULL' ELSE 'NOT NULL' END FieldContent,
      COUNT(*) FieldCount
    FROM
      TheTable
    GROUP BY
      CASE WHEN Field IS NULL THEN 'NULL' ELSE 'NOT NULL' END
    
    0 讨论(0)
提交回复
热议问题