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

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

    Select Sum(Case When processed_timestamp IS NULL
                             Then 1
                             Else 0
                     End)                                                               not_processed_count,
              Sum(Case When processed_timestamp Is Not NULL
                             Then 1
                             Else 0
                     End)                                                               processed_count,
              Count(1)                                                                total
    From table
    

    Edit: didn't read carefully, this one returns a single row.

提交回复
热议问题