Limit records in a query by group

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jackiefm
    New Member
    • Oct 2007
    • 15

    Limit records in a query by group

    I have a crosstab query that I need the returned records to be limited to the top 10 for each group. How can I accomplish this? My sql
    Code:
    TRANSFORM Count(Violation.Driver) AS CountOfDriver
    SELECT Driver.RegionName, Driver.Code
    FROM (Driver INNER JOIN Violation ON Driver.Code = Violation.Driver) INNER JOIN Terminal ON Driver.TerminalName = Terminal.Address1
    WHERE (((Violation.Description)="11 hour" Or (Violation.Description)="14 hour" Or (Violation.Description)="60 hr / 70 hr" Or (Violation.Description)="falsification"))
    GROUP BY Driver.RegionName, Driver.Code
    PIVOT Violation.Description;
  • puppydogbuddy
    Recognized Expert Top Contributor
    • May 2007
    • 1923

    #2
    Originally posted by jackiefm
    I have a crosstab query that I need the returned records to be limited to the top 10 for each group. How can I accomplish this? My sql

    TRANSFORM Count(Violation .Driver) AS CountOfDriver
    SELECT Driver.RegionNa me, Driver.Code
    FROM (Driver INNER JOIN Violation ON Driver.Code = Violation.Drive r) INNER JOIN Terminal ON Driver.Terminal Name = Terminal.Addres s1
    WHERE (((Violation.De scription)="11 hour" Or (Violation.Desc ription)="14 hour" Or (Violation.Desc ription)="60 hr / 70 hr" Or (Violation.Desc ription)="falsi fication"))
    GROUP BY Driver.RegionNa me, Driver.Code
    PIVOT Violation.Descr iption;
    Save your crosstab query, then do a select query using your crosstab as the data source, following the instructions in this link.

    Comment

    • jackiefm
      New Member
      • Oct 2007
      • 15

      #3
      I have created the queries and reports as required but the query keeps returning that Access does not recognize the criteria as a valid field name or expression.

      Comment

      • puppydogbuddy
        Recognized Expert Top Contributor
        • May 2007
        • 1923

        #4
        Can you post the sql of your new query so I can look at it? Thanks.

        Comment

        Working...