sql count null values in a column code example

Example 1: how to count null values in sql

SELECT COUNT(1) FROM my_table WHERE my_column IS NULL;

Example 2: sql count null values in all columns

SELECT sum(CASE WHEN column_A IS NULL THEN 1 ELSE 0 END) A,
       sum(CASE WHEN column_B IS NULL THEN 1 ELSE 0 END) B
FROM my_table;

Example 3: how to count null values

HOW TO COUNT NULL VALUES
List<String> list = new ArrayList(Arrays.asList
                              ("Java",null,"Python",null, "Ruby"));
CollectionUtils.filter(list, PredicateUtils
                           .nullPredicate()); ==> keeps only nulls
System.out.println(list.size());

Tags:

Misc Example