Doo*_*ius 0 sql t-sql sql-server
我正在尝试找到一种方法来查找类似“1234”、“12345”、“9876”、“7654”等的字符串。因此,具有向上或向下连续数字的值。3 个字符(例如 123、321)到 10 个字符(0123456789、9876543210)之间的任意字符
INSERT INTO #TmpTbl
Values ('12345')
,('45678')
,('44569')
,('987654')
,('748376')
,('123')
,('0123456789')
,('9876543210')
Run Code Online (Sandbox Code Playgroud)
预期成绩
您可以使用LIKE它来查找模式。例如:
select *
from t
where '0123456789' like concat('%', a, '%')
or '9876543210' like concat('%', a, '%');
Run Code Online (Sandbox Code Playgroud)
结果:
a
----------
12345
45678
987654
123
0123456789
9876543210
Run Code Online (Sandbox Code Playgroud)
请参阅db<>fiddle中的示例。