sql排序问题

来源:互联网 发布:知父莫若子是什么意思 编辑:程序博客网 时间:2024/05/18 01:59

select * from Test



select name as 员工姓名,score as 员工业绩,排名=(SELECT COUNT(DISTINCT Score) FROM Test WHERE Score >= a.score)
from Test a where score in
(
select distinct top 3 score from Test order by score desc
)
order by 员工业绩 desc
go

 


select name as 员工姓名,score as 员工业绩,排名=(SELECT COUNT(Score) FROM Test WHERE Score >a.Score) + 1
from Test a where score in       
(
select distinct top 3 score from Test order by score desc
)
order by 员工业绩 desc
go

 


SELECT *,Place=(SELECT COUNT(DISTINCT Score) FROM Test WHERE Score >= a.Score)
FROM Test a
ORDER BY Place

效果依次是:

 

 

原创粉丝点击