Can I get the position of a record in a SQL result table?

后端 未结 6 900
日久生厌
日久生厌 2020-12-16 02:35

If I do something like

SELECT * FROM mytable ORDER BY mycolumn ASC;

I get a result table in a specific order.

Is there a way in SQL

6条回答
  •  爱一瞬间的悲伤
    2020-12-16 02:53

    You can count the number of records where the value that you are sorting on has a lower value than the record that you know the key value of:

    select count(*)
    from mytable
    where mycolumn < (select mycolumn from mytable where key = 42)
    

提交回复
热议问题