Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql ISNULL如果一列或两列为空,则为0_Mysql_Sql - Fatal编程技术网

Mysql ISNULL如果一列或两列为空,则为0

Mysql ISNULL如果一列或两列为空,则为0,mysql,sql,Mysql,Sql,我有一个类似这样的SQL语句 ISNULL(revenue - expense, 0) 我正在尝试查找我的“收入”和/或“费用”列中是否有一列或两列为空。如果其中一个或两个都为空,则返回0。但是,我不断收到错误消息。您可以使用: 此外,您还可以在MySQL中使用函数: 使用下面的合并功能 Select Coalesce(revnue,0)-coalesce(expense,0) from t 你的声明表明: COALESCE(revenue - expense,

我有一个类似这样的SQL语句

ISNULL(revenue - expense, 0) 
我正在尝试查找我的“收入”和/或“费用”列中是否有一列或两列为空。如果其中一个或两个都为空,则返回0。但是,我不断收到错误消息。

您可以使用:

此外,您还可以在MySQL中使用函数:


使用下面的合并功能

     Select  Coalesce(revnue,0)-coalesce(expense,0)  
     from t

你的声明表明:

COALESCE(revenue - expense, 0) 
但是,逻辑表明您可能真的想要:

COALESCE(revenue, 0) - COALESCE(expense, 0) 
也就是说,如果值为NULL,则将每个值单独视为0

请注意,数字值并非真正为空,这意味着一个空字符串。它们为空。

可能的副本请参见:
COALESCE(revenue - expense, 0) 
COALESCE(revenue, 0) - COALESCE(expense, 0)