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;
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 ;
group by is unnecessary. The where clause limits the output to one category. If you always want one row, then leave out the group by.