opposite of “top” in sql server, without using order by, there are no keys/indices

前端 未结 5 1409
孤街浪徒
孤街浪徒 2021-01-18 06:14

I want to retrieve the bottom 10 results from a sql server table. I want them to be the last 10 records that were inserted, how can I do this ?

I want to write

5条回答
  •  长情又很酷
    2021-01-18 06:41

    https://stackoverflow.com/a/10636585/2858777

    with bottom as(
    select top 4 * from tbl order by n desc ) select * from bottom order by n

    Data source:

    | N | |----| | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | | 10 |

    Output:

    | N | |----| | 7 | | 8 | | 9 | | 10 |

提交回复
热议问题