I have a data set similar to this:
id assign_no last_attempt DPD Status
--------------------------------------------------
1 123456 12/31/2010 100 On Hold
2 123456 12/10/2010 50 On Hold
3 123456 12/5/2010 25 On Hold
4 123457 12/28/2010 90 Closed
5 123457 12/10/2010 80 Closed
6 123457 12/5/2010 60 Closed
Note there are two basic sets of records here: 123456 and 123457. What I want is to get the most recent attempts in these two groups. The desired set returned would be this:
id assign_no last_attempt DPD Status
---------------------------------------------------
1 123456 12/31/2010 100 On Hold
4 123457 12/28/2010 90 Closed
I've tried all kinds of aggregate queries and it always returns the same 6 rows instead of the 2 that I want.
SELECT assign_no, MAX(last_attempt) AS last_attempt,
DPD, Status
FROM dbo.Test
GROUP BY assign_no, DPD, Status
(This doesn't work)
Thanks for all your help!
id assign_no last_attempt DPD Status
--------------------------------------------------
1 123456 12/31/2010 100 On Hold
2 123456 12/10/2010 50 On Hold
3 123456 12/5/2010 25 On Hold
4 123457 12/28/2010 90 Closed
5 123457 12/10/2010 80 Closed
6 123457 12/5/2010 60 Closed
Note there are two basic sets of records here: 123456 and 123457. What I want is to get the most recent attempts in these two groups. The desired set returned would be this:
id assign_no last_attempt DPD Status
---------------------------------------------------
1 123456 12/31/2010 100 On Hold
4 123457 12/28/2010 90 Closed
I've tried all kinds of aggregate queries and it always returns the same 6 rows instead of the 2 that I want.
SELECT assign_no, MAX(last_attempt) AS last_attempt,
DPD, Status
FROM dbo.Test
GROUP BY assign_no, DPD, Status
(This doesn't work)
Thanks for all your help!