有一学生成绩表内容如下:
id    name   score1001  张三    95
1002  李四    70
1005  王五    85
1008  刘二    85
1010  李刚    59学生成绩排名后如下:
id    name  score  排名
1001  张三   95      1
1005  王五   85      2
1008  刘二   85      2
1002  李四   70      3
1010  李刚   59      4求查询语句,本人是菜鸟,多谢各位大大 帮忙!

解决方案 »

  1.   

    select id ,name,score,row_number()over(order by score desc) 排名 from student
      

  2.   


    select id,name,score,row,dense_rank()over(order by score) from tablename ;
      

  3.   

    看错了 用dense_rank()分析函数
      

  4.   


    Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 
    Connected as SYS
    SQL> 
    SQL> with student as
      2  (
      3  select 1001 id, '张三' name,95 score from dual union all
      4  select 1002 ,'李四' ,70 score from dual union all
      5  select 1005 ,'王五', 85 score from dual union all
      6  select 1008, '刘二', 85 score from dual union all
      7  select 1010 ,'李刚', 59 score from dual
      8  )
      9  select id ,name,score,dense_rank()over(order by score desc) from student
     10  /        ID NAME      SCORE DENSE_RANK()OVER(ORDERBYSCORED
    ---------- ---- ---------- ------------------------------
          1001 张三         95                              1
          1005 王五         85                              2
          1008 刘二         85                              2
          1002 李四         70                              3
          1010 李刚         59                              4SQL> 
      

  5.   

    SQL> ed
    已写入 file afiedt.buf  1  with tb as(
      2  select 1001 id,'张三' name, 95 score from dual
      3  union all
      4  select 1002,'李四',70 from dual
      5  union all
      6  select 1005,'王五',85 from dual
      7  union all
      8  select 1008,'刘二',85 from dual
      9  union all
     10  select 1010,'李刚',59 from dual)
     11  select id,name,score,dense_rank() over (order by score desc) 排名
     12* from tb
    SQL> /        ID NAME      SCORE       排名
    ---------- ---- ---------- ----------
          1001 张三         95          1
          1005 王五         85          2
          1008 刘二         85          2
          1002 李四         70          3
          1010 李刚         59          4
      

  6.   

    多谢各位了。。select id,name,score,row,dense_rank()over(order by score) from tablename ;