SQL仅获取域名

时间:2018-10-19 16:04:32

标签: mysql sql

从===>到

https://www.google.com/asdkasjdhask  ===> google
https://google.com/asdkasjdhask  ===> google
https://google.comasd/asdkasjdhask  ===> google
https://www.google.be/dddasdkasjdhask  ===> google
https://www.google.tr/asdkasjdhask  ===> google
https://www.google.as/asdkasjdhask  ===> google
https://www.google.ur/asdkasjdhask  ===> google
https://www.bing.com/asdkasjdhask  ===> bing
https://bing.com/asdkasjdhask  ===> bing
https://bing.comasd/asdkasjdhask  ===> bing
https://www.bing.be/dddasdkasjdhask  ===> bing
https://www.bing.tr/asdkasjdhask  ===> bing
https://www.bing.as/asdkasjdhask  ===> bing
https://www.bing.ur/asdkasjdhask  ===> bing

和计数 例如google的7,bing的6,youtube的2等。

我尝试过SELECT count(*) .......并没有达到我想要的效果

Mysql

1 个答案:

答案 0 :(得分:2)

您可以使用文本函数提取域:

SELECT LEFT(c, INSTR(c, '.')-1) AS site, COUNT(*)
FROM (SELECT REPLACE(REPLACE(url,'https://', ''), 'www.', '') AS c
     FROM tab) sub
GROUP BY LEFT(c, INSTR(c, '.')-1);

db<>fiddle demo