排序和排名 [英] Sorting and Ranking

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

问题描述



有关如何同时对4列进行排序和排名的任何信息.

我有4列
选择薪水,交通津贴,HouseAllw,工资中的现金
第一列应为asc-第一列应为数字1点
第二列应该是asc-第1列应该是数字1点
2将获得2 pnts
last将获取最近一次回收的cnt
第三列应为desc-与1列和2列相反
第4列应为asc-与第1列相同


结果记录1 1,000(1分)500(1分)2,000(1分)
记录2 1,500(2分)800(2分)1,000(2分)

谢谢
Dabuskol

Hi,

Any info on how to sort and rank 4 columns at the same time.

I have 4 columns
Select Salary, TransAllowance, HouseAllw, Cash from Payroll
1st column should be asc - the first will get number 1 pts
2nd column should be asc - 1 first will get number 1 pts
2 will get 2 pnts
last will get the last number of recound cnt
3rd column should be desc - opposite of 1 and 2 columns
4th column should be asc - same as 1st column


Result Record 1 1,000 (1pt) 500 (1pts) 2,000 (1 pts)
Record 2 1,500 (2pt) 800 (2pts) 1,000 (2 pts)

Thanks
Dabuskol

推荐答案

我找到了答案.您必须使用RANK()
以下示例:

I found the answer. You have to use the RANK()
Example below:

select originator,holdtime,hubtime,
       RankHubTime = ROW_NUMBER() OVER(ORDER BY hubtime ASC),
       RankHoldTime = ROW_NUMBER() OVER(ORDER BY holdtime ASC),
 from #tmp1



结果:



Result:

Col1    Col2    Col3           col4    col5<br />
Test1	304925	59674601	1	2<br />
Test2	353072	62857242	2	4<br />
Test3	490172	24462340	4	3<br />
Test4	975875	15261822	3	4



谢谢



Thanks


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

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