mysql实现取字段值中某个字符之前的值

例如字符串 abc/def/gh/ijk 取最后一个/之前的值即abc/def/gh

实现函数:substring_index、length、replace

select substring_index(‘abc/def/gh/ijk’,’/’,length(replace(‘abc/def/gh/ijk’,’/’,’//’))-length(‘abc/def/gh/ijk’))

关键点解析:length(replace(‘abc/def/gh/ijk’,’/’,’//’))-length(‘abc/def/gh/ijk’)求出/的个数

    原文作者:Lan-Forever
    原文地址: https://blog.csdn.net/you_two/article/details/120567121
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞