Oracle: How to count null and non-null rows

后端 未结 6 2104
猫巷女王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:12

    This worked well for me for counting getting the total count for blank cells on a group of columns in a table in oracle: I added the trim to count empty spaces as null

    SELECT (sum(case 
               when trim(a) is null Then 1
               else 0
           end)) +
       (sum(case
               when trim(b) is null 
               else 0
           end)) +
       (sum(case
               when trim(c) is null 
               else 0
           end)) as NullCount
    FROM your_table
    

    Hope this helps

    Cheers.

提交回复
热议问题