WHERE条件下的SQL SUBSTRING

时间:2019-07-07 06:31:41

标签: mysql sql

`Traceback (most recent call last):
 File "site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line   149, in _
 _init__
 File "ctypes\__init__.py", line 348, in __init__
 OSError: [WinError 126] The specified module could not be found

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
 File "liveyoutbe.py", line 2, in <module>
 File "<frozen importlib._bootstrap>", line 961, in _find_and_load
 File "<frozen importlib._bootstrap>", line 950, in  _find_and_load_unlocked
 File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
 File "c:\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
 line 627, in exec_module
 exec(bytecode, module.__dict__)
 File "site-packages\vlc.py", line 207, in <module>
 File "site-packages\vlc.py", line 163, in find_lib
 File "site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line  151, in _
_init__
 __main__.PyInstallerImportError: Failed to load dynlib/dll 'libvlc.dll'. Most pr
 obably this dynlib/dll was not found when the application was frozen.
 [6032] Failed to execute script liveyoutbe`

查询:-

create table numbers (number varchar(10));
insert into numbers (number) values
('1234123452'),
('5532003644'), 
('1122330505'),                                      
('1103220311'),                                     
('1103000011'),
('1103020012');                                    

结果:-

  

没有要显示的结果。


预期结果

  

1234123452

2 个答案:

答案 0 :(得分:3)

SUBSTRING()的第三个参数是长度,而不是结束位置。所以应该是:

SELECT * FROM numbers 
WHERE SUBSTRING(Number,1,4) = SUBSTRING(Number,5,4)

答案 1 :(得分:0)

假设您使用的是MySQL 8+,则可以在这里利用REGEXP_LIKE

SELECT *
FROM numbers
WHERE REGEXP_LIKE(Number, '^(.{4})\\1';

模式^(.{4})\\1匹配并捕获前四个字符,然后断言这些相同的字符紧随其后出现。