我正在尝试使用以下语句将0替换为0但不返回recrods而不是catid和0。
select ifnull(count(*),0) as days, catid from mytable where Id=48 and catId=7
group by mytable.catId;
答案 0 :(得分:3)
据我所知,COUNT(*)永远不会返回NULL。如果没有记录,则返回0.
答案 1 :(得分:1)
count(*)
永远不会返回NULL
,因此您不需要任何条件逻辑:
select count(*) as days, catid
from mytable
where Id = 48 and catId = 7
group by mytable.catId;
也许您的问题是查询没有返回行。如果是这样,您可以省略group by
。然后查询将始终返回一行:
select count(*) as days, catid
from mytable
where Id = 48 and catId = 7 ;