Oracle: Display row number with 'order by' clause

前端 未结 4 1114
独厮守ぢ
独厮守ぢ 2021-02-02 17:14

I wonder how could i print a row number for sql statement where is using order. Currently i tried ROWNUM but as i understand it works only for unsorted result set.

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-02 17:51

    Hello. I wonder how could i print a row number for sql statement where is using order. Currently i tried ROWNUM but as i understand it works only for unsorted result set.

    To be clear (somebody might get it wrong). It does work (but not in the way you expect). The problem with it is that it "attaches" the ROWNUM before the sort and you get your records but not in consecutive ROWNUM records. Why? Because

    The first record that meets the where criteria in a select statement is given rownum=1

    This is really good example how select / order mechanism works.

提交回复
热议问题