sql - sorting large amounts of urls by top domain in mysql -
sql - sorting large amounts of urls by top domain in mysql -
a mysql database i'm working has thousands of urls. now, lot of urls same domain, each 1 have differing sub-domains , page names. e.g.
somewebsite.com/gj29sjw somewebsite.com/29shw0a somewebsite.com/92jslwa anothersite.net/jfdkden anothersite.net/hj2892j anothersite.net/282j290 etc...
is there query or syntax can utilize both grouping urls , count them in largest first order, without subdomains , page names. ideally, after run count query, need get:
somewebiste.com | 345 anothersite.net | 289
you utilize substring_index create query simple; take 2 lastly period separated groups before first slash;
select substring_index(substring_index(url, '/', 1), '.', -2) site, count(*) cnt mytable grouping site; an sqlfiddle test with.
note good performance on query, i'd recommend storing site name separately, doing calculations on each ro not give ultimate performance.
mysql sql sorting url count
Comments
Post a Comment