In MS Transact SQL, let's say I have a table (Orders):
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 is: for each client, the average order amount for the last two orders. Therefore, for client number 1, I should get 7.00 (and not 7.83).
I looked at this for an hour (inside the larger problem that I solved), and I think my brain was frozen. Help solve a simple problem?
source
share