表[tbl_post]有id,說明[long_text]。子串IN mysql需要取詞
的描述字段具有以下值:
Hi how r u? #TravelingtheWorld #TravelingtheWorld
Hi how r u? #Traveled
bla bla bla travelbybus blah blah
blah blah blah @travelegency blah blah
the intelligence demonstrated in during tests iterations
blah blah blah testing blahh
blah blah blah tested blahh
我們有@和#功能。
如果我嘗試搜索的價值 「測試」,我需要 「測試/檢驗/檢測」
SELECT SUBSTRING_INDEX(CONCAT(
'$ipstring',
SUBSTRING_INDEX(LOWER('description'), LOWER('$ipstring'), -1)
) , ' ',1) AS 'mystring'
FROM tbl_post
WHERE `description` LIKE '$ipstring%'
OR `description` LIKE '% $ipstring%'
OR `description` LIKE '%#$ipstring%'
OR `description` LIKE '%@$ipstring%'
輸入搜索字符串的響應
$ipstring = "travel"
我在這裏獲得輸出
- 已旅行
- TravelingtheWorld
- travelbybus
- travelegency
輸入搜索字符串
$ipstring = "te"
我在這裏獲得輸出
- terations >>>在這裏,我需要 「測試」(即智能在測試迭代期間顯示)
- 測試
- 測試
查詢:
首先查詢
SELECT SUBSTRING_INDEX (CONCAT( 'travel', SUBSTRING_INDEX(LOWER('Hi how r u? *TravelingtheWorld *TravelingtheWorld'), LOWER('travel'), -1) ) , ' ',1) AS 'mystring'
第二個查詢
SELECT SUBSTRING_INDEX (CONCAT( 'te', SUBSTRING_INDEX(LOWER('the intelligence demonstrated in during tests iterations'), LOWER('te'), -1) ) , ' ',1) AS 'mystring'
如果我添加一個空格「」之前,輸入字符串「TE」,我會得到「測試」
SELECT SUBSTRING_INDEX (CONCAT(
'te',
SUBSTRING_INDEX(LOWER('the intelligence demonstrated in during tests iterations'), LOWER(' te'), -1)
) , ' ',1) AS 'mystring'
但對於第一次查詢:如果我添加一個空格「輸入字符串之前」 'travelling'
SELECT SUBSTRING_INDEX (CONCAT(
'travel',
SUBSTRING_INDEX(LOWER('Hi how r u? *TravelingtheWorld *TravelingtheWorld'), LOWER(' travel'), -1)
) , ' ',1) AS 'mystring'
...我沒有收到「TravelingtheWorld」
我看到'$ ipstring':你使用PHP嗎?如果是這樣,PHP解決方案適合你嗎? – trincot
是的,我們正在使用php Mysql但我們需要在單個查詢中輸出mysql而不是在php中。在此先感謝 –
即使不是,如果您將PHP函數作爲參數查詢結果集並將修改它並將其重新返回?在純粹的MySql中,這將是巨大的代碼,我擔心效率會更低。 – trincot