donglie9067 2014-02-12 13:03
浏览 105
已采纳

使用或在where子句中为零或为null

I have a query, i want to display the result if two of my fields are equal at zero or null.

foreach ($query=$db->query("SELECT *,
t1.CMD_ID, t1.CMD_CLT_RS, t1.CMD_CLT_ID,
t2.CLT_ID, t2.CLT_CODE
FROM sous_commandes 
LEFT OUTER JOIN commandes AS t1 ON (t1.CMD_ID=sous_commandes.SCMD_CMD_ID)
LEFT OUTER JOIN client AS t2 ON (t2.CLT_ID=t1.CMD_CLT_ID)
WHERE SCMD_FRN_ID = '$frn_id' AND SCMD_FACT_TOTAL_HT = '0' || IS NULL AND SCMD_FACT_TOTAL_TTC = '0' || IS NULL
ORDER BY STR_TO_DATE(SCMD_DATE, '%d/%m/%Y') DESC") as $donnees):

I tried to use || IS NULL but it doesn't work. No result are display. Thanks.

  • 写回答

2条回答 默认 最新

  • duanpanzhu2910 2014-02-12 13:04
    关注

    change

    SCMD_FACT_TOTAL_HT = '0' || IS NULL
    

    to

    (SCMD_FACT_TOTAL_HT = '0' OR  SCMD_FACT_TOTAL_HT  IS NULL)
    

    same for SCMD_FACT_TOTAL_TTC of course.

    EDIT

    You could also do

    COALESCE(SCMD_TOTAL_HT, '0') = '0'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?