select count(*) from [forum-master] where forumid=9 --group by forumid 这行不用就行了
select count(*) from [forum-master] where forumid=9 group by All forumid --只有这样能返回,但是如果表里有多个forumid,将返回多行0
select count(*) from [forum-master] where forumid=9 --group by All forumid --既然你的条件已经限制forumid=9,那group by已经没有意义,去掉group by,一样可以实现你的查询要求,而且也可以返回0
isnull(count(*),0) 这样是不行的,因为返回的不是null,而是没有返回 group by All forumid --只有这样能返回,但是如果表里有多个forumid,将返回多行0----------这样的情况到是没有考虑到用下面的可以:create table [forum-master]( ForumID int, Master varchar(20) ) goinsert into [forum-master] values(8,'yan') insert into [forum-master] values(10,'yan1') select count(*) from (select forumid from [forum-master] where forumid=9 group by forumid) a
where forumid=9
group by forumid返回
----------- (所影响的行数为 0 行)
where forumid=9
group by all forumid--group by all不去掉null的列返回
-----------
0
---------------------------------
ISNULL
使用指定的替换值替换 NULL。语法
ISNULL ( check_expression , replacement_value ) 参数
check_expression将被检查是否为 NULL的表达式。check_expression 可以是任何类型的。replacement_value在 check_expression 为 NULL时将返回的表达式。replacement_value 必须与 check_expresssion 具有相同的类型。
where forumid=9
--group by forumid 这行不用就行了
where forumid=9
group by All forumid --只有这样能返回,但是如果表里有多个forumid,将返回多行0
where forumid=9
--group by All forumid --既然你的条件已经限制forumid=9,那group by已经没有意义,去掉group by,一样可以实现你的查询要求,而且也可以返回0
这样是不行的,因为返回的不是null,而是没有返回
group by All forumid --只有这样能返回,但是如果表里有多个forumid,将返回多行0----------这样的情况到是没有考虑到用下面的可以:create table [forum-master](
ForumID int,
Master varchar(20)
)
goinsert into [forum-master] values(8,'yan')
insert into [forum-master] values(10,'yan1')
select count(*) from
(select forumid from [forum-master]
where forumid=9
group by forumid) a