Count如果为null,则应显示零值

时间:2014-04-10 07:28:15

标签: mysql

我正在使用MYSQL DB

当我选择没有日期的情况时,我有桌面工作顺序,我需要显示零,如

select * from joborder;
10

select * from joborder where jobid='ID';
null
它应该显示0?

2 个答案:

答案 0 :(得分:0)

您可以在mysql查询中使用IFNULL

LIKE select IFNULL((select ID from joborder where jobid='ID'),0);

答案 1 :(得分:0)

我假设你需要它存在的值,而0它是null。 按照以下方式使用您的查询:

SELECT IFNULL(order_value,0) AS 'order_value' FROM joborder WHERE jobid='ID';

检查以下内容:

SELECT IFNULL(t21.n1,0) n1 ,t22.n2 FROM t1 AS t21 RIGHT JOIN (SELECT n2 FROM t2) t22 ON t22.n2=t21.n1;
相关问题