SELECT msg1, result,(SELECT COUNT(*) FROM QJ_Select_Result WHERE a.result <= result) AS ssort FROM QJ_Select_Result a ORDER BY ssort出的问题就是.要是有个并列第一的就会把他们都写成第二名
declare @t table(stu_id int,stud_name varchar(20),chinese decimal(10,2)) insert @t select 1,'jfk',77 union all select 2,'Jk',63.2 union all select 3,'djfkd',44 union all select 4,'fddk',63.2 union all select 5,'fd',75 union all select 6,'gg',77 select *,chineseorder = (select count(*) from @t where chinese > a.chinese) + 1 from @t a order by chineseorder
SELECT msg1, result,(SELECT COUNT(*)+1 FROM QJ_Select_Result WHERE a.result < result) AS ssort FROM QJ_Select_Result a ORDER BY ssort
insert @t
select 1,'jfk',77 union all
select 2,'Jk',63.2 union all
select 3,'djfkd',44 union all
select 4,'fddk',63.2 union all
select 5,'fd',75 union all
select 6,'gg',77
select *,chineseorder = (select count(*) from @t where chinese > a.chinese) + 1 from @t a
order by chineseorder