【问题标题】:How to use substring_index in match against如何在匹配中使用 substring_index
【发布时间】:2017-08-02 17:17:32
【问题描述】:

我需要一个 sql 查询来使用 mysql 匹配 (index:fulltext) 来提取所有相关的“网球礼物”产品,但是在使用 substring_index 仅从 product_attributes 中获取类别部分以匹配 @987654321 时出现以下错误@字符串

product_attributes value = {"category":"Tennis > Gifts > Necklace", "seasons":{"months":["January","February"]}}

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

错误

#1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 3 行的 '(substring_index(product_attributes, 'category', -1), '"', 1)) ' 附近使用正确的语法

如何仅将类别值与搜索词匹配,感谢任何帮助。提前致谢。

【问题讨论】:

  • 这个问题根本没有PHP。 php 标签无关紧要。

标签: mysql sql


【解决方案1】:

你可以试试这个

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

【讨论】:

  • 感谢您的建议,但我仍然收到错误消息:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 3 行的 '(substring_index(product_attributes, 'category', -1), '\"', 1)) aga' 附近使用正确的语法
猜你喜欢
  • 2014-11-22
  • 2013-08-11
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
  • 2023-01-17
  • 2017-01-14
  • 2017-11-28
  • 1970-01-01
相关资源
最近更新 更多