2010-11-12 48 views
1

我需要在SQLite中編寫向後匹配的查詢。有什麼辦法可以做到嗎?在SQLite中向後匹配

我的例子是波紋管:

SELECT * FROM urls where forwordurl LIKE '%www.google.com%' 

工作正常,但我需要爲波紋管

SELECT * FROM urls where 'www.google.com' LIKE %forwordurl% 

有沒有辦法做到這一點?

回答

4

這工作:

SELECT * FROM urls WHERE 'www.google.com' LIKE '%' || forwordurl || '%' 

例子:

[C:\Temp] :sqlite3 test.db 
SQLite version 3.6.20 
Enter ".help" for instructions 
Enter SQL statements terminated with a ";" 
sqlite> create table urls (forwordurl text); 
sqlite> insert into urls (forwordurl) values ('google'); 
sqlite> select * from urls where 'www.google.com' like '%' || forwordurl || '%'; 
google 
sqlite> ^Z 
+0

它不工作,我做了測試。 – Chandana 2010-11-12 10:09:48

+2

對不起,我的錯誤是,SQLite中的字符串連接運算符不是'+',它是'||',編輯了反映的答案。 – 2010-11-12 10:16:47

+0

它工作正常。非常感謝您的支持。 :) – Chandana 2010-11-12 10:20:48