数据库 mysql sql 语句实现模糊查询 SELECT * FROM table WHERE keyword LIKE '%xxx%'

like 关键字 结合百分号% 实现 模糊查询

原本精确查询: 匹配 title 为 testadgddsdf 的数据

SELECT * FROM table WHERE title='testadgddsdf'

现在模糊查询:

  1. 匹配title 字段包以 tes 为起始的数据:
SELECT * FROM table WHERE title LIKE 'tes%'
  1. 匹配title 字段以 tes 为结尾的数据:
SELECT * FROM table WHERE title LIKE '%tes'
  1. 匹配 title 字段包含 tes 为开头、任意位置、结尾的数据
SELECT * FROM table WHERE title LIKE '%tes%'
posted @ 2022-04-08 14:22  智商感人  阅读(559)  评论(0)    收藏  举报