3

我有一个查询,它提供了应用于数据库中事物的不同类别的细分:

select categories, count(*) from products 
group by categories

数据是这样的:

NULL                56
                    42
FooCategory         12
BlahCategory        2

我想分组NULL<blank>

NoCategory          98
FooCategory         12
BlahCategory        2
4

2 回答 2

8

尝试

select ISNULL(categories,'') as Categories, count(*) from products 
group by ISNULL(categories,'')

更新

有关所需参数,请参见此处

ISNULL(检查表达式,替换值)

于 2012-11-21T15:27:13.150 回答
4

尝试

select categories, 
case when categories is null or categories = ' ' 
then 'noCategory' else categories end as grouped,
count(*) 
from products 
group by grouped
于 2012-11-21T15:30:27.043 回答