【问题标题】:Getting the last three records from SQLite database从 SQLite 数据库中获取最后三个记录
【发布时间】:2019-07-01 13:27:42
【问题描述】:

我有一个数据库,我想从中获取最后 3 条记录。例如,如果我有 1、2、3、4、5、6、... 10、11、12、13、14 行,无论顺序如何,我都想要 12、13、14(12、13、14对我来说等于 14,13,12)。 我试图在此链接上关注另一个问题Android SQLite Query - Getting latest 10 records 但我得到的只是显示数据库的前 3 行。

这是我的查询

String query2 ="select * from (select * from USERS order by ID ASC limit 3)";

【问题讨论】:

  • 使用desc 而不是asc
  • 顺便说一句,SELECT语句不需要加倍。

标签: android database sqlite android-sqlite


【解决方案1】:

在任何情况下,您都可以按rowid 降序排序并获得 3 行:

select * from USERS order by rowid desc limit 3

如果要按特定列排序:

select * from USERS order by columnname desc limit 3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多