Reputation: 19
I want to generate Dense_Rank on a particular column but I want to provide default Rank on few value but the sequence should not break any suggestion.
Upvotes: 0
Views: 110
Reputation: 23797
What you want is:
select *,
dense_rank() over (order by case when id <> 3 then id end)-1 as Ranking
from test
order by id;
Probably this was what you meant in your comment:
IF OBJECT_ID('tempdb..#test') IS NOT NULL
DROP TABLE #test
create table #test (id int);
insert into #test (id) values (1),(2),(3),(4),(4),(5),(6),(7);
with mx(id) as
(select max(id) from #test),
data(id, idrev) as (select t.id, mx.id - t.id + 1 from #test t, mx)
select id,
dense_rank() over (order by case when id <> 3 then idrev end)-1 as Ranking
from data order by id;
Upvotes: 1