需求:匹配出location里是/xx/xx/xx/xx=xx的格式,然后过滤掉后面的xx=xx
举例:/apps/b_adv/prod/druid_pl_ppl/eventType=ALL/y=2019/m=12/d=21
解题思路:首先我们用正则匹配到符合条件的数据
1.
select location from test where location REGEXP '/.*=';
然后截取等号之前的内容,这里用到的是substring
2.
.select substring_index(location,'=',1),location from test where location REGEXP '/.*=';
将最后一个分隔符后面的内容去掉举例论述
3.
select REVERSE(SUBSTR(REVERSE('/apps/hdmi-prod/b_bis/search/data/fact/sesn_type') FROM INSTR(REVERSE('/apps/hdmi-prod/b_bis/search/data/fact/sesn_type'),'/')+1));
得到的结果:/apps/hdmi-prod/b_bis/search/data/fact
我们只需要把上面的字符串换成主要截取的字段名称即可
SELECT (select REVERSE(SUBSTR(REVERSE(substring_index(location,'=',1)) FROM INSTR(REVERSE(substring_index(location,'=',1)),'/')+1))),location
FROM test
WHERE location REGEXP '/.*='