首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在MySQL中是否有解析URL域名的解决方案

在MySQL中是否有解析URL域名的解决方案
EN

Stack Overflow用户
提问于 2015-07-22 19:04:27
回答 1查看 71关注 0票数 0

我有一张桌子

Table1:

代码语言:javascript
复制
ID  URL
1   http://msdn.microsoft.com/en-us/library/9a6a2sxy.aspx
2   http://en.wikipedia.org/wiki/mysql
3   http://wrong-url
4   http://www.chami.com/tips/internet/042599i.html
5   http://www.chami.com

我想添加一个列来记录URLS的域。我想要一张这样的桌子:

代码语言:javascript
复制
ID  URL                                                        Domain
1   http://msdn.microsoft.com/en-us/library/9a6a2sxy.aspx      microsoft.com
2   http://en.wikipedia.org/wiki/mysql                         wikipedia.org
3   http://wrong-url                                           null
4   http://www.chami.com/tips/internet/042599i.html            chami.com
5   http://www.chami.com                                       chami.com

有人能提供解决方案吗?

EN

回答 1

Stack Overflow用户

发布于 2015-07-22 19:09:37

您可以使用substring_index()来完成此操作

代码语言:javascript
复制
select substring_index(substring_index(url, '/', 3), substring_index, '.', -2) as domain

这不适用于第三个示例。为此,请使用case来检测模式。类似于:

代码语言:javascript
复制
select (case when url like 'http//%.%.%/%'
             then substring_index(substring_index(url, '/', 3), substring_index, '.', -2)
        end) as domain
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31561298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档