我有一个充满URL的表.该网址是在各种格式:http://foo.com,http://bar.foo.com,http://foo.com/bar等,但我只是在域名本身感兴趣,所以在这种情况下:foo.com.我想要做的是选择此表中存在多少次域名.所以类似于:
SELECT "whatever the domain is in field 'url'", COUNT(*) AS count
FROM table_with_urls
GROUP BY "whatever the domain is in field 'url'"Run Code Online (Sandbox Code Playgroud)
Stack Overflow上有一些类似的问题,但没有真正回答这个问题.我不能使用LIKE或匹配REGEXP,因为我不(总是)寻找特定的域名来匹配,但大多数情况下我只想要表中的所有域名以及总计数.
这可能使用MySQL吗?
小智 9
我有同样的问题,这就是我做的:
select SUBSTRING(url from 1 for locate('/',url ,10)-1),count(*) from url_list group by SUBSTRING(url from 1 for locate('/',url ,10)-1);
Run Code Online (Sandbox Code Playgroud)