Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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 WHERE子句中的ISNULL(值,0)_Mysql_Where_Isnull - Fatal编程技术网

Mysql WHERE子句中的ISNULL(值,0)

Mysql WHERE子句中的ISNULL(值,0),mysql,where,isnull,Mysql,Where,Isnull,我有这样的要求: SELECT sc.no, scl.quantite, scl.description, scl.poids, scl.prix, sl_ref.refsl, sl_ref.codetva, sl_ref.tauxtva, sl_ref.compte FROM shop_commande AS sc, shop_commande_ligne AS scl, selectline_ref AS sl_ref WHERE sc.id = scl.shop_commande_i

我有这样的要求:

SELECT sc.no, scl.quantite, scl.description, scl.poids, scl.prix, sl_ref.refsl, sl_ref.codetva, sl_ref.tauxtva, sl_ref.compte 
FROM shop_commande 
AS sc, shop_commande_ligne AS scl, selectline_ref AS sl_ref 
WHERE sc.id = scl.shop_commande_id 
AND sl_ref.refshop = ISNULL(scl.shop_article_id, 0) 
AND sc.id NOT IN (SELECT id_command FROM selectline_flag)
有时,在sl_shop_article_id中,有一个空值。我想用0替换它,因此该子句:

sl_ref.refshop = scl.shop_article_id
即使scl.shop\u article\u id为空,也可以工作。为此,我尝试使用ISNULL函数,但它使请求出错,因此出现错误:

1582-对本机函数“ISNULL”的调用中的参数计数不正确


如何使用它?

我相信您正在尝试使用
IFNULL()
函数。如果将
ISNULL
替换为
IFNULL
,则应修复您的查询

SELECT 
    sc.no
    , scl.quantite
    , scl.description
    , scl.poids
    , scl.prix
    , sl_ref.refsl
    , sl_ref.codetva
    , sl_ref.tauxtva
    , sl_ref.compte 
FROM shop_commande 
AS sc, shop_commande_ligne AS scl, selectline_ref AS sl_ref 
WHERE sc.id = scl.shop_commande_id 
AND sl_ref.refshop = IFNULL(scl.shop_article_id, 0) 
AND sc.id NOT IN (SELECT id_command FROM selectline_flag)
我建议您进一步使用
COALESCE()
而不是
IFNULL()
,因为
COALESCE()
是SQL标准的一部分(而
IFNULL()
不是)


您可以在这里看到
ISNULL()
IFNULL()
函数之间的区别,感谢您的链接和快速回答!正如Ike所说,COALESCE是SQL标准的一部分,我将使用他的答案,但您的答案也很好!工作真的很好,现在没有关于合并,所以谢谢!
SELECT sc.no, scl.quantite, scl.description, scl.poids, 
scl.prix, sl_ref.refsl, sl_ref.codetva, sl_ref.tauxtva, sl_ref.compte 
FROM shop_commande 
AS sc, shop_commande_ligne AS scl, selectline_ref AS sl_ref 
WHERE sc.id = scl.shop_commande_id 
AND sl_ref.refshop = COALESCE(scl.shop_article_id, 0) 
AND sc.id NOT IN (SELECT id_command FROM selectline_flag)