关于SQL语句里面被除数为0的问题

2025-04-08 10:29:49
推荐回答(3个)
回答1:

简单做的话,可以在除数:(count(distinct case when b.status=1 then b.taskid  end)+count(case when b.taskid=0 and b.status=0  then b.taskid end)) 的外层加一个decode

 decode((count(distinct case when b.status=1 then b.taskid  end)+count(case when b.taskid=0 and b.status=0  then b.taskid end)),0,1,(count(distinct case when b.status=1 then b.taskid  end)+count(case when b.taskid=0 and b.status=0  then b.taskid end)))

回答2:

case when xxx=0 then 1 else xxx end 这样么?

回答3:

用 case when then else 试试 应该可以的