如表a:
姓名   年龄
胡锦涛  50
温家宝  30
江泽民  60我要按年龄从小到大排序要生成一个序号列
如:
姓名   年龄   序号
温家宝  30     1
胡锦涛  50     2
江泽民  60     3这个SQL 语句怎么写?

解决方案 »

  1.   

    select 姓名,年龄,row_number()over(order by 年龄) 
    from ....
      

  2.   

    或者
    select t.*,rownum
    (select * from table order by age)t
      

  3.   

    select 姓名,年龄,row_number()over(order by 年龄) 序号 
    from a;
      

  4.   

    恩 对!上面已经有答案了!select t.*,rownum from a order by 年龄 。如果要插入的话,按照这个查询的结果在对表a的数据进行更新。
      

  5.   

    select 姓名,年龄,row_number()over(order by 年龄) 序号  
    from a;