有mysql路径字段,

E:\code-py-download\价\图片\2021005017\3\3-68590-8915ad8329a942f38fcb74306212a067-0.png

 

 

 如何取最后一个 \  前面部分?

SELECT LOCATE('\\',path_names_png),path_names_png FROM `yfyj`

select substring_index(path_names_png,'\\',-1) from yfyj
SELECT SUBSTRING_INDEX('and_this_may_go_like_this_too', '_', -1);
length对中文长度不好
SELECT path_names_png, LEFT(path_names_png, LENGTH(path_names_png) - LOCATE('\\', REVERSE(path_names_png))) from yfyj

char_length中文长度OK
SELECT path_names_png, LEFT(path_names_png, char_length(path_names_png) - LOCATE('\\', REVERSE(path_names_png))) from yfyj