我有一个查询,如果我的两个字段等于零或为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):
我尝试使用|| IS为NULL但不起作用。没有显示结果。 谢谢。
答案 0 :(得分:3)
变化
SCMD_FACT_TOTAL_HT = '0' || IS NULL
到
(SCMD_FACT_TOTAL_HT = '0' OR SCMD_FACT_TOTAL_HT IS NULL)
当然SCMD_FACT_TOTAL_TTC
也一样。
修改强>
您也可以
COALESCE(SCMD_TOTAL_HT, '0') = '0'
答案 1 :(得分:1)
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' || isnull(SCMD_FACT_TOTAL_HT) AND SCMD_FACT_TOTAL_TTC = '0' || isnull(SCMD_FACT_TOTAL_TTC)
ORDER BY STR_TO_DATE(SCMD_DATE, '%d/%m/%Y') DESC") as $donnees):