Mysql 多个关键词查询,并且按照数量多少排序
文章来源地址https://www.toymoban.com/diary/sql/200.html
直接上代码,多个字段搜索,关键词1,关键词2,关键词3
// 多个字段 SELECT *, ( (IF( CONCAT_WS(" ", title, keywords, description) LIKE "%关键词1%", 1, 0)) + (IF( CONCAT_WS(" ", title, keywords, description) LIKE "%关键词2%", 1, 0)) + (IF( CONCAT_WS(" ", title, keywords, description) LIKE "%关键词3%", 1, 0)) ) AS sort FROM table_name WHERE CONCAT_WS(" ", title, keywords, description) REGEXP "关键词1|关键词2|关键词3" ORDER BY sort DESC // 单个字段 SELECT *, (IF(title LIKE "%关键词%",1,0)) AS sort FROM table_name ORDER BY sort DESC
文章来源:https://www.toymoban.com/diary/sql/200.html
到此这篇关于Mysql多个关键词模糊查询并且按照出现的次数多少进行排序的文章就介绍到这了,更多相关内容可以在右上角搜索或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!