I'm working with some data in snowflake and I'm attempting to count the number of null values in a given column. Would pivoting across each column name, using a sum(case when col_name is null then 1 else 0 end) as my aggregate work here? Or, is there a more efficient way of counting the total number of nulls for all columns in a table?
| col 1 | col 2 | col 3 |
|---|---|---|
| val 1 | val 2 | val 3 |
| null | null | val 4 |
| null | val 5 | val 6 |
This table should somehow count the nulls in each row like this.
| col 1 null count | col 2 null count | col 3 null count |
|---|---|---|
| 2 | 1 | 0 |
The biggest thing is some tables have 100's of columns and having to type each column name over and over again won't work.