我有一个查询,它提供了应用于数据库中事物的不同类别的细分:
select categories, count(*) from products
group by categories
数据如下:
NULL 56
42
FooCategory 12
BlahCategory 2
我想将NULL
和<blank>
NoCategory 98
FooCategory 12
BlahCategory 2
答案 0 :(得分:5)
尝试
select ISNULL(categories,'') as Categories, count(*) from products
group by ISNULL(categories,'')
<强>更新强>
在此处查看所需参数
答案 1 :(得分:3)
试
select categories,
case when categories is null or categories = ' '
then 'noCategory' else categories end as grouped,
count(*)
from products
group by grouped