我在这个页面上发现了一个类似的问题,Mysql查询从urls中提取域
SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(target_url, '/', 3), '://', -1), '/', 1), '?', 1) AS domain但是这个代码的结果是不正确的。
'www.abc.com‘'lalala.one.google.com’'two.one.test.com‘
我需要得到最后两个词,分隔符是点。
我需要这个结果
'abc.com‘'google.com’'test.com‘
发布于 2019-09-14 16:46:02
使用subtring()和substring_index()
set @url = 'https://stackoverflow.com/questions/57937363/how-to-remove-subdomain-from-url-in-mysql';
select substring_index(substring_index(substring(@url, locate('://', @url) + 3), '/', 1), '.', -2) as domain见演示。
结果:
domain
-----------------
stackoverflow.comhttps://stackoverflow.com/questions/57937363
复制相似问题