Mysql query to extract domains from urls

前端 未结 12 2121
小鲜肉
小鲜肉 2020-12-08 08:21

sorry for my english

i have this query to extract domain from urls

SELECT SUBSTRING(LEFT(url, LOCATE(\'/\', url, 8) - 1), 8) AS domain...
         


        
12条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 08:32

    The query needs to account for no trailing '/'

    IF( LOCATE('/', replace(url,'http://', '') ) > 0 , SUBSTRING(replace(url,'http://', ''), 1, LOCATE('/', replace(url,'http://', '') ) - 1), replace(url,'http://', '')) AS domain
    

提交回复
热议问题