[英]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.