Grouping null and empty values as one in sql
sql
Solution
try
select categories,
case when categories is null or categories = ' '
then 'noCategory' else categories end as grouped,
count(*)
from products
group by grouped
Problem
I have a query which provides a breakdown of different categories applied to things in the database: ``` select categories, count(*) from products group by categories ``` The data comes like this: ``` NULL 56 42 FooCategory 12 BlahCategory 2 ``` I would like to group `NULL` and `<blank>` ``` NoCategory 98 FooCategory 12 BlahCategory 2 ```