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

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

    [T-SQL]:

    select [case], count(*) tally
    from (
      select 
      case when [processed_timestamp] is null then 'null'
      else 'not null'
      end [case]
      from myTable
    ) a 
    

    And you can add into the case statement whatever other values you'd like to form a partition, e.g. today, yesterday, between noon and 2pm, after 6pm on a Thursday.

提交回复
热议问题