count where group by语句 返回值若为空,怎么显示出0
sql="selecteditor,COUNT(1)ascountfromNewsWHEREcheckked=1groupbyeditor"想要将返回值为空的显示为0应该...
sql="select editor, COUNT(1) as count from News WHERE checkked = 1 group by editor"
想要将返回值为空的显示为0 应该怎么写? 展开
想要将返回值为空的显示为0 应该怎么写? 展开
展开全部
换个思路吧,例如下面这样:
select editor,sum(case when checkked = 1 then 1 else 0 end) as count from News group by editor
select editor,sum(case when checkked = 1 then 1 else 0 end) as count from News group by editor
更多追问追答
追问
这样写我也试过,但是调用和不行
追答
不能调用是因为结果为空,所以取不了数,只要不让结果为空就可以了,试试下面这句:
select editor,count from(select editor, COUNT(1) as count from News WHERE checkked = 1 group by editor union all select top 1 null as editor,0 as count from News WHERE isnull((select count(1) from News WHERE checkked = 1),0)=0 )a
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询