如何从表中检索最后2条记录?(How to retrieve the last 2 records from table?)
我有一张有n个记录的表格
如何从SQL中的表中检索第n条记录和第(n-1)条记录而不使用派生表?
我曾尝试使用ROWID作为
select * from table where rowid in (select max(rowid) from table);它给出了第n个记录,但我也想要第(n-1)条记录。 除了使用max,derived table and pseudo columns之外max,derived table and pseudo columns还有其他方法max,derived table and pseudo columns
谢谢
I have a table with n number of records
How can i retrieve the nth record and (n-1)th record from my table in SQL without using derived table ?
I have tried using ROWID as
select * from table where rowid in (select max(rowid) from table);It is giving the nth record but i want the (n-1)th record also . And is there any other method other than using max,derived table and pseudo columns
Thanks
最满意答案
select * from (select * from my_table order by rowid) where rownum <= 2对于N和M之间的行:
select * from ( select * from ( select * from my_table order by rowid ) where rownum <= M ) where rownum >= N select * from (select * from my_table order by rowid) where rownum <= 2and for rows between N and M:
select * from ( select * from ( select * from my_table order by rowid ) where rownum <= M ) where rownum >= N更多推荐
发布评论