Results 1 to 3 of 3
  1. #1
    RECrerar is offline Novice
    Windows XP Access 2002
    Join Date
    Nov 2012
    Posts
    2

    Select all books greater than on month old with morethan 10 sales

    Hey All,



    Several years ago I used to be okay at this but it is a log time since I did any SQL and so I was wondering if you could help.

    I have the following two tables and I want to get a list of all books that have been available for more than a month that have had more than 10 orders.

    Code:
    Product_id name rrp available_from
    101 Book1 12 12/11/2011
    102 Book2 1 10/10/2012
    103 Book3 13 20/11/2012
    order_id product_id quantity order_price Dispatch Date
    1001 1001 5 60 22/11/2011
    1002 1003 11 143 19/11/2012
    1003 1001 7 84 10/11/2012

    I have the following SQL which works but I was wondering if it needs all the fields it has (I mainly built in through the access desgin view query and I know this has a tendency to put in more information that it needs, so I was wondering if there is a way to shorten it.

    Code:
    SELECT Orders.ProductID, Sum(Orders.Quantity) AS SumOfQuantity, Products.Available_from, Products.ProductName
    FROM Products INNER JOIN Orders ON Products.ProductID = Orders.ProductID
    GROUP BY Orders.ProductID, Products.Available_from, Products.ProductName
    HAVING (((Sum(Orders.Quantity))>10) AND ((Products.Available_from)<=DateAdd("m",-1,Date())));

    Thanks
    Robyn

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Available_from and Sum(Quantity) fields aren't required to be displayed. If you don't want to show them, uncheck them in the query designer. Instead of Group By for the Available_from field, select Where on the Total row.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    RECrerar is offline Novice
    Windows XP Access 2002
    Join Date
    Nov 2012
    Posts
    2
    Thanks,

    That helped a lot, the SQL is not much more understandable.

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

Similar Threads

  1. Select receipts from last month
    By Baldeagle in forum Queries
    Replies: 12
    Last Post: 11-29-2012, 03:16 PM
  2. Replies: 5
    Last Post: 06-30-2011, 02:24 AM
  3. How to Benchmark The Best Month Sales
    By jasonman in forum Queries
    Replies: 4
    Last Post: 11-13-2010, 12:30 PM
  4. Replies: 7
    Last Post: 07-19-2010, 08:55 AM
  5. Replies: 0
    Last Post: 04-03-2009, 01:15 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