我有一张桌子
Table1:
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的域。我想要一张这样的桌子:
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有人能提供解决方案吗?
发布于 2015-07-22 19:09:37
您可以使用substring_index()来完成此操作
select substring_index(substring_index(url, '/', 3), substring_index, '.', -2) as domain这不适用于第三个示例。为此,请使用case来检测模式。类似于:
select (case when url like 'http//%.%.%/%'
then substring_index(substring_index(url, '/', 3), substring_index, '.', -2)
end) as domainhttps://stackoverflow.com/questions/31561298
复制相似问题