Results 1 to 5 of 5
  1. #1
    Assamita is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2016
    Posts
    4

    Select top 5 from each country

    Hi,
    I have an excel file with sales order amounts for different customers from different countries. That's a linked table to an access, where I've been able to create a query that sums up the amount for each customer in each country, sorted first by country, then by amount.
    How can now create a query that only retreives the top 5 customers for each country? If I could just modify the existing query, that would be great, but if I need a new query linked to the first one it's ok too. I just made an SQL query like this:
    Code:
    SELECT TOP 5 BW_top5customersbyinvoice.[Company code Name], BW_top5customersbyinvoice.[Sold-to party], BW_top5customersbyinvoice.[Sold-to party Name], BW_top5customersbyinvoice.[SumOfNet Sell Price Invoice]
    FROM BW_top5customersbyinvoice;
    But this only shows the first 5 rows of the query BW_top5customersbyinvoice (which is the one I was talking earlier).

    Any suggestion?



    Thank you

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848

  3. #3
    Assamita is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2016
    Posts
    4
    thank you orange. I've read the article, but I can't figure it out to work with my file in particular. Anyway, since I have to export this to excel anyway, I've seen I can do it with a pivot table.
    Thank you anyway.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    This is his generic SQL. The subquery is in blue.

    Code:
    SELECT Orders.CustomerID, Orders.OrderDate, Orders.OrderID
    FROM Orders
    WHERE Orders.OrderID IN
       (SELECT TOP 3 OrderID                            
       FROM Orders AS Dupe                              
       WHERE Dupe.CustomerID = Orders.CustomerID        
       ORDER BY Dupe.OrderDate DESC, Dupe.OrderID DESC) 
    ORDER BY Orders.CustomerID, Orders.OrderDate, Orders.OrderID;

  5. #5
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2013
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    This link should show you specifically how to do that

    http://www.datapigtechnologies.com/f...spergroup.html

Please reply to this thread with any new information or opinions.

Similar Threads

  1. drop down selections (country/state/city)
    By fastforded in forum Access
    Replies: 11
    Last Post: 03-26-2015, 07:40 AM
  2. Replies: 1
    Last Post: 09-09-2014, 11:29 PM
  3. How to find Country by using the email address?
    By jamesfranklin in forum Programming
    Replies: 2
    Last Post: 03-07-2013, 07:07 AM
  4. DLookup Function for City/Region/Country?
    By cap.zadi in forum Forms
    Replies: 6
    Last Post: 11-22-2012, 11:16 AM
  5. Country Code Calculation
    By nchesebro in forum Forms
    Replies: 14
    Last Post: 06-15-2011, 02:03 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