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