Oracle: How to count null and non-null rows

后端 未结 6 2041
猫巷女王i
猫巷女王i 2021-02-04 01:38

I have a table with two columns that might be null (as well as some other columns). I would like to count how many rows that have column a, b, both and neither colu

6条回答
  •  感情败类
    2021-02-04 02:00

    Something like this:

    SELECT sum(case 
                   when a is null and b is null then 1
                   else 0
               end) as both_null_count,
           sum(case
                   when a is null and b is not null then 1
                   else 0
               end) as only_a_is_null_count
    FROM your_table
    

    You can extend that for other combinations of null/not null

提交回复
热议问题