I am having some issues with getting this working. I have a table with this data in it.
| DateStarted | Field9 | Field2 | ID | Field6 |
----------------------------------------------------------------------------------------
| 2013-04-15 09:23:00 | TEST1 | TEST2 | 1 | 2000 |
| 2013-04-08 09:23:00 | TEST1 | TEST2 | 2 | 180 |
| 2013-04-15 09:23:00 | TEST2 | TEST3 | 3 | 1000 |
| 2013-04-04 09:23:00 | TEST2 | TEST3 | 7 | 80 |
| 2013-04-03 09:23:00 | TEST2 | TEST4 | 5 | 70 |
What my end goal is was to have the last two dates for the value for Field9 be returned so that I could subtract the value of Field6 for each unique instance of Field9. Below is an example of the return.
| DateStarted | Field1 | Field2 | ID | SUB |
----------------------------------------------------------------------------------------
| 2013-04-15 09:23:00 | TEST1 | TEST2 | 1 | 1820 |
| 2013-04-15 09:23:00 | TEST2 | TEST3 | 3 | 920 |
So for the second row it took the two greatest dates and then took the value of field6 and subtracted them returning just the one row.