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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 rownumber reverse

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 _test

create 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 _test
order by s, b

Resultset:

A1 B1 1 1 1 <-- ???
A2 B1 1 1 4
A2 B2 2 1 3
A2 B2 3 2 2
A2 B3 4 1 1
A3 B1 1 1 3
A3 B1 2 2 2
A3 B3 3 1 1
A4 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]

Go to Top of Page
   

- Advertisement -