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 |
|
kristijanv
Starting Member
8 Posts |
Posted - 2010-03-01 : 04:24:33
|
| i'm looking a way to get rownumber reverse. Any ideas?Example:drop table _testcreate table _test (s CHAR(30), b char(20))insert into _test (s , b) select 'A1','B1'insert into _test (s , b) select 'A2','B1'insert into _test (s , b) select 'A2','B2'insert into _test (s , b) select 'A2','B2'insert into _test (s , b) select 'A2','B3'insert into _test (s , b) select 'A3','B1'insert into _test (s , b) select 'A3','B1'insert into _test (s , b) select 'A3','B3'insert into _test (s , b) select 'A4','B1'SELECT s, b,ROW_NUMBER() OVER (PARTITION BY s ORDER BY s,b) AS Seq1,ROW_NUMBER() OVER (PARTITION BY s,b ORDER BY s,b) AS Seq2??? AS Seq3 --row number desc or somthn?FROM _testorder by s, bResultset:A1 B1 1 1 1 <-- ???A2 B1 1 1 4A2 B2 2 1 3A2 B2 3 2 2A2 B3 4 1 1A3 B1 1 1 3A3 B1 2 2 2A3 B3 3 1 1A4 B1 1 1 1 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-03-01 : 04:28:43
|
ROW_NUMBER() OVER (PARTITION BY s ORDER BY b desc) KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|
|
|