有沒有辦法編寫一個sql查詢來查找字段值是給定字符串的子字符串的所有行。mysql:找到有字段是「字符串」的子字符串的行
例子:
table names
Name | Nickname
rohit iamrohitbanga
banga rohitnick
sinan unur
查詢應該是這樣的
select * from names where Name is a substring of "who is rohit"; // to get first row
select * from names where Nickname is a substring of "who is rohitnick"; // to get second row
select * from names where Name is a substring of "who is unur and banga"
or Nickname is substring of "who is unur and banga"; // to get second and third row
這怎麼可能?
如果這是不可能的,那麼我將不得不在java中實現這種行爲。我正在使用jdbc:mysql驅動程序來連接到數據庫。
更新 您的解決方案的工作
現在有點扭曲。 如果我們想檢查字段的子字符串是否作爲我們指定的字符串的子字符串出現。
select * from names where Name is a substring of "who is sina"; // to get third row
對於那些提供答案以便事後更改標準的人來說,這是不尊重的。 – 2010-01-23 20:24:06
@iamrohitbanga:我同意'OMG小馬'。海報不會收到通知,說明你改變了你的問題,所以大多數人不會更新他們的答案。如果您的初始問題得到解決,請接受答案並隨時添加另一個問題。此外,我沒有看到你的新查詢('名稱是東西的子字符串)和原始查詢('名稱是東西的子字符串) – 2010-01-23 21:17:47
同意!你是對的 – 2010-01-24 07:00:20