2014-11-20 68 views
1

我正在嘗試使用IFNULL來確定在where子句中使用列,但我不相信我正確地做了它。有人有任何建議嗎?使用IFNULL選擇Mysql

SELECT * FROM bdesclookuptable 
WHERE LOWER('Santa Clause Home Address') LIKE CONCAT('%',LOWER(lText),'%') 
AND LOWER('Santa Clause Home Address') LIKE CONCAT('%',LOWER(IFNULL(plusand,'ilikethispaintingoverhead')),'%') 
AND LOWER('Santa Clause Home Address') NOT LIKE CONCAT('%',LOWER(IFNULL(andnot,'ilikethispaintingoverhead')),'%'); 

table 
id lText   bbid ttype andnot  plusand 
16 Home Address 11 13  null  Santa 
17 Home Address 11 13  Work  Santa 
18 Home Address 12 15  Mrs Clause null 

我想這個查詢拉只紀錄的16

+0

add'and id = 16'?解釋你想從你的數據庫中提取什麼plz – 2014-11-20 16:38:54

+0

@BenjaminPoignant我會認爲它不是完全是16,而是關於屬性的組合。其他一切都是毫無意義的。 – glglgl 2014-11-20 16:44:03

回答

1

一個id你有3個條件。他們都必須成功才能成功。

條件1滿足所有三條記錄,因爲Home Address包含在Santa Clause Home Address中。

條件2滿足16和17. 18失敗,因爲plusand被替換爲未包含在模式中的長字。

條件3再次滿足所有三個。

所以,你應該得到16和17

爲了避免17,你應該做的條件之一失敗吧,E。 G。包含在字符串中的值爲andnot,以使其失敗。