繁体   English   中英

如何在访问SQL中将每组的前3名拉高

[英]How to pull top 3 per group in access SQL

我正在尝试将一个小组中的前三名表演者拉到一起。 我不确定如何在Access中做到这一点,我需要的是让每个小组都进入前三名。

http://allenbrowne.com/subquery-01.html

我尝试了这些子查询,但是它们给了我一条错误消息。 有一个更好的方法吗?

这是为了提高关键字的效果。

表字段是

Keyword | Campaign | Ad Group |  Clicks | Impressions 

我希望每个广告组的点击次数排名前三。 我也想要排名前3的印象,但是一旦我知道如何进行点击,就可以根据需要进行修改。 我试图变得像

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];

它返回所有条目,而不是前3个。

我想你很亲密:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM