I am trying replace null with 0 with following statement but returns no recrods instead of of catid supplied and 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. It returns 0 if there is no record.
count(*)
never returns NULL
, so you don't need any conditional logic:
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
. Then the query will always return one row:
select count(*) as days, catid
from mytable
where Id = 48 and catId = 7 ;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.