I am not sure exactly how to approach this.
I have two tables. customer and order
customer has a last contact date
I want the average of the top 10 sales within 60 days of the last contact.
I can get the top ten sales easily enough with a top ten query for the customer and date range using both tables, but to get the top ten, i have to specify the customer.
So... i decided to use this query as a subquery...
but to average it, i need another subquery
so i end up with basically:
And... access doesn't like the double level subquery asking for the value of customer ID and lastcontact.
Any suggestions?
Thanks in advance
Lisa
I have two tables. customer and order
customer has a last contact date
I want the average of the top 10 sales within 60 days of the last contact.
I can get the top ten sales easily enough with a top ten query for the customer and date range using both tables, but to get the top ten, i have to specify the customer.
So... i decided to use this query as a subquery...
but to average it, i need another subquery
so i end up with basically:
Code:
SELECT customer.customerID,
customer.lastContact,
(select avg(AvgContactSales.topamount)
from (SELECT top 10 order.amount as topamount
FROM [order]
WHERE (((order.saledate)>[customer]![lastContact])
AND ((order.saledate)<=([customer]![lastContact]+60))
AND ((order.customerId)=[customer]![customerId]))
order by order.amount desc))) AS AvgContactSales)
FROM customer;
And... access doesn't like the double level subquery asking for the value of customer ID and lastcontact.
Any suggestions?
Thanks in advance
Lisa