2014-02-12 72 views
0

我有一個查詢,我想顯示結果如果我的兩個字段是相等的零或空。使用或在where子句爲零或爲空

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

變化''||爲'或'' – krishna

+0

'||爲[** **有效(HTTPS:/ (AND)(SCMD_FACT_TOTAL_HT ='0'或SCMD_FACT_TOTAL_HT IS NULL)AND(SCMD_FACT_TOTAL_TTC ='0'或SCMD_FACT_TOTAL_TTC IS NULL)在MySQL –

+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
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): 
相關問題