SQL to output line number in results of a query

后端 未结 5 527
忘了有多久
忘了有多久 2021-01-07 17:38

I would like to generate a line number for each line in the results of a sql query. How is it possible to do that?

Example: In the request

select di         


        
5条回答
  •  盖世英雄少女心
    2021-01-07 18:33

    In Oracle

    SQL> select row_number() over (order by deptno) as rn
      2         , deptno
      3  from
      4     ( select distinct deptno
      5            from emp
      6          )
      7  /
    
            RN     DEPTNO
    ---------- ----------
             1         10
             2         20
             3         30
    
    SQL>
    

提交回复
热议问题