ISNULL(value, 0) in WHERE clause MYSQL

前端 未结 2 1187
我寻月下人不归
我寻月下人不归 2020-12-19 18:39

I have this requets:

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         


        
相关标签:
2条回答
  • 2020-12-19 19:07
    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)
    
    0 讨论(0)
  • 2020-12-19 19:12

    I believe you are trying to use the IFNULL() function. IF you replaced ISNULL with IFNULL that should fix your query.

    I suggest you go one step further and use COALESCE() instead of IFNULL(), since COALESCE() is part of the SQL standard (and IFNULL() is not).

    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)
    
    0 讨论(0)
提交回复
热议问题