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 |
Tyork
Starting Member
6 Posts |
Posted - 2011-09-20 : 09:37:59
|
Need code to group by F1 but grab only the rownums with the greatest value. row number is not an actual field. sample table below and required query results below.RowNum F1 F2-- -- --1 1 12 1 23 1 34 1 45 1 56 1 67 1 78 2 19 2 210 2 511 2 412 2 3Code would generate:RowNum F1 F2-- -- --7 1 712 2 3Any help would be appreciated.Tyork |
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2011-09-20 : 09:45:31
|
Hello,Do you have a clustering index? Without one, I cannot see how you can determine the ordering of the data blocks. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-09-20 : 09:53:02
|
select rownum, f1, f2from (select rownum, f1, f2, row_number() over (partition by f1 order by rownum desc) as recid from dbo.table1) AS dwhere recid = 1 N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|