With a ‘standard’ Orders table I am trying to find out how far back in time it was that a specific client purchased a certain numbers of items.
Order ID Items Client Date
-------- ----- ------ ----
1 1 Fred 26/04/2012
2 3 John 25/04/2012
3 2 Fred 20/04/2012
4 5 Fred 18/04/2012
5 3 Fred 14/04/2012
6 4 Fred 10/04/2012
So I want to know the time frame covered by the last 10 items purchased by Fred, starting from now and working back.
In this instance I would be trying to identify that Order IDs 1, 3, 4 & 5 added together take me to (or just past) my target total of 10 items, so the date I am looking for is 14/04/2012.
Is there a simple solution to this?
Off the top of my head…
NB if you want to start gathering other information such as what orders are in the set, then Matt Fenwick’s solution is cleaner.