表结构如下:Student

一个student表有姓名和成绩两个字段。查询某个学生的姓名和成绩以及排名。

要求得到的结果如下:

一个student表有姓名和成绩两个字段。查询某个学生的姓名和成绩以及排名。

sql语句如下:

 SELECT   1+(SELECT   COUNT(distinct   score)    
                            FROM   (select   *  
                                            from   student)   AS   T1    
                          WHERE   score   >   T2.score)   as   名次   ,[name],score  
        FROM   (select   *  
                        from   student 
                    )   AS   T2     ORDER   BY   T2.score   desc

 

一个student表有姓名和成绩两个字段。查询某个学生的姓名和成绩以及排名。

 

sql如下:

 SELECT   1+(SELECT   COUNT(distinct   score)    
                            FROM   (select   *  
                                            from   student)   AS   T1    
                          WHERE   score   >   T2.score)   as   名次   ,[name],score  
        FROM   (select   *  
                        from   student  
                    )   AS   T2     where T2.[name]='jtome1'
  ORDER   BY   T2.score   desc

 

 

精简版本如下:

select t1.[name],t1.score,(select count(distinct score)+1 from student as t2 where score>t1.score) as 名次
from student as t1
where t1.[name] ='jtome1'
order by t1.score desc;

相关文章:

  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-17
  • 2022-12-23
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
  • 2021-11-14
相关资源
相似解决方案