[英]Replace null with value in mysql query with 0
I am trying replace null with 0 with following statement but returns no recrods instead of of catid supplied and 0. 我正在尝试使用以下语句将null替换为0,但不返回Recrod,而不是提供的catid和0。
select ifnull(count(*),0) as days, catid from mytable where Id=48 and catId=7
group by mytable.catId;
As far as I know, COUNT(*) does never return NULL. 据我所知,COUNT(*)永远不会返回NULL。 It returns 0 if there is no record.
如果没有记录,则返回0。
count(*)
never returns NULL
, so you don't need any conditional logic: count(*)
从不返回NULL
,因此您不需要任何条件逻辑:
select count(*) as days, catid
from mytable
where Id = 48 and catId = 7
group by mytable.catId;
Perhaps your issue is that the query is returning no rows . 也许您的问题是查询没有返回任何行 。 If so, you can leave out the
group by
. 如果是这样,您可以在之前省略
group by
。 Then the query will always return one row: 然后查询将始终返回一行:
select count(*) as days, catid
from mytable
where Id = 48 and catId = 7 ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.