我想使用,如果在SQL查詢語句:使用,如果在MySQL查詢語句
我想要什麼:
if(tractions_delivery.send_date_id !=0){
date_send_commodities.id = tractions_delivery.send_date_id
}
我的查詢:
from
tractions_delivery,user_address,province,city,date_send_commodities,users
WHERE
tractions_delivery.tr_id = $tr_id
AND
tractions_delivery.address_id = user_address.id
AND
user_address.province_id = province.id
AND
user_address.city_id = city.id
AND
//not work
(tractions_delivery.send_date_id IS NOT 0 date_send_commodities.id = tractions_delivery.send_date_id)
AND
users.id = user_address.user_id
你能澄清一下這個查詢是應該做的嗎? – Mureinik
... AND CASE WHEN tractions_delivery.send_date_id!= 0 THEN date_send_commodities.id = tractions_delivery.send_date_id ELSE 1 = 1 END AND users.id = user_address.user_id – iiro
什麼是「不是0」?你可以寫'IS NOT NULL'或'<> 0'。 – i486