Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    accessmatt is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    199

    Help with a Top 15 by two different dimensions

    Hi, it's been a while since I've used Access so I'm a bit out of practice what I'm trying to do I think should be pretty easy. Basically I have two dimensions in my table (Landing Page, Keyword) and I'm trying to group each of them by the top 15 # of Sessions. Kind of a two step query that first finds top the Top 15 Landing Pages by Sessions and then finds the Top 15 Keywords by Sessions just for those Landing Pages.

    I'm able to create the first query and get the top 15 Landing Pages by Sesssions. It looks like this:



    Code:
    SELECT TOP 15 Table1.[Landing Page],Table1.Sessions From Table1 
    GROUP BY Table1.[Landing Page], Table1.Sessions
    ORDER By Table1.Sessions DESC
    Can anyone help me run the second step and get the top 15 keywords just for these Landing Pages?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    Q1 pull random top15 recs

    so you want Q2 to count Landing Page, in Q1
    and Q3 to count Keywords in Q1
    ?

  3. #3
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    So you have a table, [Table1], with the fields [Landing page], [Sessions], [Keyword], and presumable an [ID]. You want to query the Top 15 keywords for EACH of the top 15 Landing pages.

    Do I understand you correctly?

    If so could you explain more in general what this is and what the table describes because something seems off... denormalized.

  4. #4
    accessmatt is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    199
    @kd2017,

    That's right. The table looks like this:

    [ID],[Landing page], [Sessions], [Keyword]

    and what I want is the top 15 keywords for each of the top 15 Landing Pages

    Any help would be appreciated.
    Thanks!

  5. #5
    accessmatt is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    199
    @ranman256, Q1 pulls top 15 Landing Pages then from there I want to pull the Top 15 Keywords for those Landing Pages. Sorted by # of Sessions (highest to least)

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    matt,
    Do you have a few sample records you could post?

    Suggestions:

    Code:
    'TopLandingPagesBySessionCount 
    
    SELECT TOP 15 MattFinalT.LandingPage
    , Count(MattFinalT.SessionID) AS CountOfSessionID
    FROM MattFinalT
    GROUP BY MattFinalT.LandingPage
    ORDER BY Count(MattFinalT.SessionID) DESC;
    Code:
    SELECT TOP 15 MattFinalT.Keyword
    , MattFinalT.LandingPage
    , Count(MattFinalT.SessionID) AS CountOfSessionID1
    FROM MattFinalT INNER JOIN TopLandingPagesBySessionCount 
    ON MattFinalT.LandingPage = TopLandingPagesBySessionCount.LandingPage
    GROUP BY MattFinalT.Keyword, MattFinalT.LandingPage
    ORDER BY Count(MattFinalT.SessionID) DESC;
    Code:
     table_name        field_name        ordinal_position    data_type    length    
    MattFinalT    ID                        0              Long    4    
                LandingPage                1              Text            255    
                SessionID                2              Long    4    
                Keyword                    3              Text            255
    These queries do not deal with ties.
    Last edited by orange; 01-30-2021 at 08:45 AM. Reason: sample sql

  7. #7
    accessmatt is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    199
    @orange. Thanks but that doesn't quite solve it. I'm still trying to get the top 15 keywords per each of those landing pages (top LPs identified in my first query). Here's an example of the data and the two query's I'm using.

    ID Landing Page Keyword Sessions
    1 LP 1 Keyword 1 20
    2 LP 1 Keyword 2 5
    3 LP 1 Keyword 3 500
    4 LP 1 Keyword 4 10

    Query 1:
    SELECT TOP 15 Table1.[Landing Page], Sum(Table1.Sessions) AS SumOfSessionsFROM Table1
    GROUP BY Table1.[Landing Page]
    ORDER BY Sum(Table1.Sessions) DESC;
    Query 2:
    SELECT Query1.[Landing Page], Query1.SumOfSessions, Table1.Keyword, Sum(Table1.Sessions) AS SumOfSessions1FROM Table1 INNER JOIN Query1 ON Table1.[Landing Page] = Query1.[Landing Page]
    GROUP BY Query1.[Landing Page], Query1.SumOfSessions, Table1.Keyword;

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    ??Not sure why you use Sum vs Count re Sessions??

    I mocked up some data, so I'm not sure if we're measuring the same thing.

    Initially I had LandingPage then the number of sessions and then built a final table with LandingPage and record for each sessionID, and one keyword per LandingPage, SessionID.

    I had 100 LandingPages, each with its Sessions and sessionID and I selected a random Keyword from an array of 100 unique keywords and assigned that keyword to that sessionID.

  9. #9
    accessmatt is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    199
    @Orange, I'm using Sum because I ultimately want to Sum the Sessions (by Landing Page in Step 1 and by Keyword in Step 2). The more I poke on this one, the more I think the solution is to write a sub-query.

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    I'm sure the structure I set up does not mirror yours. Do you want to post a copy of your database with enough records to do some tests or at least send the table structure with some sample data.

  11. #11
    accessmatt is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    199
    @orange, sure here's an example database: https://drive.google.com/file/d/1Zm8...ew?usp=sharing

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  13. #13
    accessmatt is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    199

    attaching database example


  14. #14
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Try (I removed the space from "Landing Page")

    Code:
    SELECT table1.LandingPage
        ,table1.Keyword
        ,sum(table1.sessions) AS CountSessions
    FROM table1
    WHERE table1.keyword IN (
            SELECT TOP 15 xx.keyword
            FROM table1 AS xx
            WHERE xx.landingpage = table1.landingpage
            GROUP BY xx.landingpage
                ,xx.keyword
            ORDER BY xx.landingpage ASC
                ,sum(xx.sessions) DESC
            )
    GROUP BY landingpage
        ,keyword
    ORDER BY table1.LandingPage
        ,SUM(table1.Sessions) DESC
        ,table1.Keyword;

  15. #15
    accessmatt is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    199
    Hi @orange, thanks for trying but it's not working as expected. I'm getting prompted to enter the parameter for xx.landingpage. Am I missing something?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. querying for dimensions
    By btappan in forum Access
    Replies: 7
    Last Post: 04-25-2017, 02:58 PM
  2. Replies: 3
    Last Post: 10-20-2015, 02:03 PM
  3. Replies: 6
    Last Post: 10-01-2013, 08:23 AM
  4. Package dimensions query
    By aflamin24 in forum Queries
    Replies: 3
    Last Post: 10-23-2012, 07:26 PM
  5. code to determine correct dimensions
    By mbar in forum Programming
    Replies: 3
    Last Post: 05-03-2012, 04:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums