In MS Transact SQL, let’s say I have a table (Orders) like this:
Order Date Order Total Customer # 09/30/2008 8.00 1 09/15/2008 6.00 1 09/01/2008 9.50 1 09/01/2008 1.45 2 09/16/2008 4.50 2 09/17/2008 8.75 3 09/18/2008 2.50 3
What I need out of this is: for each customer the average order amount for the most recent two orders. So for Customer #1, I should get 7.00 (and not 7.83).
I’ve been staring at this for an hour now (inside a larger problem, which I’ve solved) and I think my brain has frozen. Help for a simple problem?
This should make it