SQL 2005中的字段排名 [英] Ranking fields in SQL 2005

查看:85
本文介绍了SQL 2005中的字段排名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要在我的SQL中进行这种排名(按VendorId和ClientId排名),我一直在使用density_rank()函数,但仍然没有运气.

你知道该怎么办吗?

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

推荐答案

hi 试试这个查询

hi try this query

select vendorID,clientid, dense_RANK() over(order by vendorID,clientid) from table_name
order by vendorID,clientid


尝试

try this

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


这篇关于SQL 2005中的字段排名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆