Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I need to have this kind of ranking in my SQL (rank by VendorId and ClientId), i've been using dense_rank() function but still there's no luck.

Do you know what to to with this?

VendorID   ClientID   Rank
100	   1001	       1
100	   1001	       1
100	   1003	       2
200	   1001	       3
200	   1003	       4
300	   1001	       5
300	   1001	       5
300	   2003	       6
Posted
Comments
Aarti Meswania 27-Sep-12 1:56am    
not clear requirements
please post some example of input-output entries.

hi try this query

SQL
select vendorID,clientid, dense_RANK() over(order by vendorID,clientid) from table_name
order by vendorID,clientid
 
Share this answer
 
Comments
akosidab 27-Sep-12 2:22am    
Thank you Abhijit :)
Maciej Los 27-Sep-12 2:41am    
+5!
try this

SQL
create table tbl(
vendorid int,
clientid int)

insert into tbl values(100,1001)
insert into tbl values(100,1001)
insert into tbl values(100,1003)
insert into tbl values(200,1001)
insert into tbl values(200,1003)

insert into tbl values(300,1001)
insert into tbl values(300,1001)
insert into tbl values(300,2003)

select vendorID,clientid, dense_RANK() over(order by vendorID,clientid) from tbl
order by vendorID,clientid
 
Share this answer
 
Comments
akosidab 27-Sep-12 2:22am    
Thank you Santhosh :)
Maciej Los 27-Sep-12 2:42am    
+5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900