2017-08-02 24 views
0

我需要一个SQL查询来拉动所有相关的“网球礼品”产品使用mysql匹配(索引:fulltext),但我得到以下错误时,使用substring_index只获得类别部分从product_attributes来匹配Tennis Gifts如何使用substring_index匹配

product_attributes值= { “类别”: “网球>礼品>项链”, “四季”:{ “月”: “一月”, “二月”]}}

select product_code 
from products 
where match(substring_index(substring_index(product_attributes, 'category', -1), '"', 1)) against ('Tennis Gifts' IN NATURAL LANGUAGE MODE) 

错误

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(substring_index(product_attributes, 'category', -1), '"', 1)) ' at line 3

我如何才能匹配搜索词的类别值,感谢任何帮助。提前致谢。

+1

有一个在这个问题上没有PHP的。 'php'标签是无关紧要的。 –

回答

0

你可以试试这个

select product_code 
    from products 
    where match(substring_index(substring_index(product_attributes, 'category', -1), '\"', 1)) 
    against ('Tennis Gifts' IN NATURAL LANGUAGE MODE) 
+0

欣赏你的建议,但我仍然收到错误:你的SQL语法错误;检查与您的MySQL服务器版本相对应的手册,以便在第3行('substring_index(product_attributes',category',-1)','',1))aga'附近使用正确的语法 –