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?

Was it helpful?

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

OTHER TIPS

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top