【问题标题】:Selecting Records in SQL using LIKE function to very specific avail使用 LIKE 函数在 SQL 中选择记录以获得非常具体的效果
【发布时间】:2022-08-10 19:24:08
【问题描述】:
我无法找到一个问题来解决如此具体的实例,但如果我遗漏了什么,我深表歉意。
如果我想选择包含特定单词 \'Apple\' 的记录,但我想确保省略可能包含单词 \'PineApple\' 的记录,LIKE 函数在这种情况下是否允许这样做,还是会存在需要进一步调理:
例如
SELECT ID, Manufacturer FROM Table1 WHERE Manufacturer LIKE \'%apple%\'
非常感谢。
标签:
sql
conditional-statements
【解决方案1】:
要做到这一点,只使用LIKE 而不使用正则表达式,您可以尝试:
SELECT ID, Manufacturer
FROM Table1
WHERE Manufacturer LIKE 'apple %' OR -- at the start of the name
Manufacturer LIKE '% apple %' OR -- in the middle
Manufacturer LIKE ' apple'; -- at the end