[英]How to pull top 3 per group in access SQL
I'm attempting to pull the top three performers in a group. 我正在尝试将一个小组中的前三名表演者拉到一起。 I'm not sure how to do this in Access, what I need is for each group to pull the top three. 我不确定如何在Access中做到这一点,我需要的是让每个小组都进入前三名。
http://allenbrowne.com/subquery-01.html http://allenbrowne.com/subquery-01.html
I've tried these subqueries however they give me an error message. 我尝试了这些子查询,但是它们给了我一条错误消息。 Is there a better way to do this? 有一个更好的方法吗?
It's for keyword performance. 这是为了提高关键字的效果。
Table fields are 表字段是
Keyword | Campaign | Ad Group | Clicks | Impressions
I want the top 3 for clicks for each ad group. 我希望每个广告组的点击次数排名前三。 I want top 3 impressions too but once I know how to do clicks I'll be able to modify it as needed. 我也想要排名前3的印象,但是一旦我知道如何进行点击,就可以根据需要进行修改。 I'm trying to get like 我试图变得像
Ad Group 1 - First Top
Ad Group 1 - Second Top
Ad Group 1 - Third Top
Ad Group 2 - First Top
Ad Group 2 - Second Top
Ad Group 2 - Third Top
etc
SELECT KeywordReport.ID, KeywordReport.Campaign, KeywordReport.[Ad group], KeywordReport.Keyword, KeywordReport.Clicks, KeywordReport.Impressions, KeywordReport.[Avg CPC], KeywordReport.[Search Impr share], KeywordReport.Cost
FROM KeywordReport
WHERE (((KeywordReport.ID) In (SELECT TOP 3 ID
FROM KeywordReport AS Dupe
WHERE Dupe.ID = KeywordReport.ID
ORDER BY Dupe.Clicks DESC)))
ORDER BY KeywordReport.[Ad group];
It is returning all entries not the top 3. 它返回所有条目,而不是前3个。
I think you were close: 我想你很亲密:
WHERE (((KeywordReport.ID) In (SELECT TOP 3 ID
FROM KeywordReport AS Dupe
WHERE Dupe.[Ad Group] = KeywordReport.[Ad Group] <-- change this line
ORDER BY Dupe.Clicks DESC)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.