1

我们已经有一个网站所有推荐的表格:(每个推荐一个条目)

String : referral
String : target
integer: date

现在,我们想使用大查询根据计数对所有推荐进行排序,例如:

referral       : target,         count:

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

大查询sql应该是什么?

4

2 回答 2

4

为什么不按两列分组?

SELECT referral, target, COUNT(*) as cnt
FROM [mydataset.referrallog] 
GROUP BY referral, target
ORDER BY cnt DESC
于 2013-01-07T21:36:24.877 回答
1

如果我说对了,那么:

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;
于 2012-12-30T21:15:41.513 回答