I have a data table that looks like this:
Landing Page | Keyword | Sessions |
---|---|---|
Landing Page 1 | Keyword 1 | 26 |
Landing Page 1 | Keyword 2 | 4 |
Landing Page 2 | Keyword 1 | 6 |
There are multiple Landing Page
s and Keyword
s. Both are dimensions and text fields. Sessions
is the amount for each of those dimensional values.
I'm trying to see the top 15 Landing Page
s measured by descending sum of Sessions
and the top 15 Keyword
s measured by descending sum of Sessions
just for those 15 Landing Page
s.
In my query, I'm trying to group on Landing Page
s and Keyword
s. I believe this can be done with a subquery but I'm having trouble writing it.
Query #1 looks like this:
SELECT TOP 15 Table1.[Landing Page], Sum(Table1.Sessions) AS SumOfSessions
FROM Table1
GROUP BY Table1.[Landing Page]
ORDER BY Sum(Table1.Sessions) DESC;
Query #2 looks like this:
SELECT Query1.[Landing Page], Query1.SumOfSessions, Table1.Keyword, Sum(Table1.Sessions) AS SumOfSessions1
FROM Query1 INNER JOIN Table1 ON Query1.[Landing Page] = Table1.[Landing Page]
GROUP BY Query1.[Landing Page], Query1.SumOfSessions, Table1.Keyword
ORDER BY Sum(Table1.Sessions) DESC;
It seems like I just need some help adding a subquery to Query #2 that selects only the top 15 Keyword
s for those top 15 Landing Page
s. Inner joining to the first query provides the top 15 Landing Page
s.
Based on my example data and considering only top 1 for both Landing Page
and Keyword
, I expect the results to look like this:
Landing Page | Keyword | Sessions |
---|---|---|
Landing Page 1 | Keyword 1 | 26 |
Landing Page 2 | Keyword 1 | 6 |