1. 程式人生 > >sql 語句if函式

sql 語句if函式

SQL語句中的if函式使用,如果滿足一個件條可以賦一個需要的值,方便程式碼判斷 eg:


SELECT *,if(ebay_excludecountrymodel.id is null,'false','true') checked 
FROM ebay_exshiplocation e left join ebay_excludecountrymodel
on e.site=ebay_excludecountrymodel.site
 and e.id= ebay_excludecountrymodel.excludecountryid
 and ebay_excludecountrymodel.site=186
where e.site=186;
 SELECT `user`.realname, if(`user`.realname IS NULL , '有值' ,'無') checked 
 from user LEFT JOIN user_other_info ON `user`.id=user_other_info.id

這裡寫圖片描述