返回列值为给定字符串前缀的所有行



我有一个tablecolumns之一是字符串(varchar(;

给定一个字符串,例如"/a/b/c/d/e/f",查找列值是该字符串前缀的所有行。 因此,如果有以下行:

idstringColum

1 ,/a/b/c/d
2 ,/e/f/a
3 ,/a/b/c/d/e/

所以我想进入结果行 1 和 3,因为两者都是/a/b/c/d/e/f 的前缀

这是你想要的吗?

select * from mytable where '/a/b/c/d/e/f' like concat(stringColum, '%')

DB小提琴上的演示

id | stringColum -: |:----------  1 |/a/b/c/d    2 ]/a/b/c/d/e/你也可以

INSTR()来表达:

select * from mytable where instr('/a/b/c/d/e/f', stringColum) = 1

使用INSTR()函数:

select * from tablename where instr('/a/b/c/d/e/f', stringColum) = 1

最新更新