Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
qman
Constraint Violating Yak Guru
442 Posts |
Posted - 2012-12-14 : 12:33:16
|
I would like to retreive records from a table for based on the maximum date for each type of record.Example table looks like thisjob complete_date notenull 2012-01-01 00:00:00.000 Test 1null 2012-02-05 00:00:00.000 Test 2null 2012-12-10 00:00:00.000 Test 3123 2012-10-11 00:00:00.000 Test 4123 2012-10-15 00:00:00.000 Test 5456 2012-12-17 00:00:00.000 Test 6My results should look like thisjob complete_date notenull 2012-12-10 00:00:00.000 Test 3123 2012-10-15 00:00:00.000 Test 5456 2012-12-17 00:00:00.000 Test 6You can see that I want to retreive only each job based on its max completed date. I was thinking of trying to use a max within a gouping, but having not luckHope this makes sense, any help would be much appreciated.Thanks! |
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2012-12-14 : 12:47:53
|
[code]Select * from(Select *,ROW_NUMBER() OVER (PARTITION BY ISNULL(Job,'N/A') Order by Completed_date desc)as Seq from Table)ZWhere Z.Seq = 1[/code] |
|
|
qman
Constraint Violating Yak Guru
442 Posts |
Posted - 2012-12-14 : 13:57:59
|
Thanks for the help, this work great.I have never used OVER/PARTITION, need to now figure out how it is working, lol.... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|