Question

We already have a table of all referral of a website: ( one entry per referral )

String : referral
String : target
integer: date

Now, we want to use big query to sort all referrals based on counts, like:

referral       : target,         count:

google.com/... : welcome.html,   28353 
bing.com/...   : welcome.html,   5334 
gmail.com/...  : about.html,     343
...

What should the big query sql be?

Était-ce utile?

La solution

why not just group by both columns?

SELECT referral, target, COUNT(*) as cnt
FROM [mydataset.referrallog] 
GROUP BY referral, target
ORDER BY cnt DESC

Autres conseils

if I got you right, so:

SELECT COUNT(path) AS path_count, path
FROM (
  SELECT concat(referrer, target) AS path
  FROM [mydataset.referrallog])
GROUP BY path ORDER BY path_count DESC;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top