Oracle: How to count null and non-null rows

后端 未结 6 2037
猫巷女王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 01:59

    COUNT(expr) will count the number of rows where expr is not null, thus you can count the number of nulls with expressions like these:

    SELECT count(a) nb_a_not_null,
           count(b) nb_b_not_null,
           count(*) - count(a) nb_a_null,
           count(*) - count(b) nb_b_null,
           count(case when a is not null and b is not null then 1 end)nb_a_b_not_null
           count(case when a is null and b is null then 1 end) nb_a_and_b_null
      FROM my_table
    

提交回复
热议问题