【问题标题】:What is the sql query in SQLite, to retrieve the records from the database table for the last week, for the last month, and for the last yearSQLite中的sql查询是什么,从数据库表中检索上周、上个月和去年的记录
【发布时间】:2011-06-16 17:47:09
【问题描述】:

我在我的项目中使用 SQLite 创建了一个数据库表,当用户单击指定的按钮时,我想从数据库中检索上周、上个月、去年的记录。但我不知道如何检索记录。是否有任何函数可以相应地获取这些记录?

【问题讨论】:

  • 时间是否作为列存储在表格中?
  • 您需要一个要从中选择的表的名称,以及该表中的一些类似时间戳的列。
  • @Tiru,请注意适当地标记您的问题。这样会有更多人看到。此外,如果您单击帮助您的答案旁边的空勾号,也不会受到伤害。
  • 感谢大家的回复
  • 您好 IIya Kogan,感谢您的建议,但现在我是这里的新用户。所以看起来不错,如果您说如何提高费率......

标签: android sql sqlite


【解决方案1】:

你需要像这样构造一个“where”子句:

ContentResolver cr = getContentResolver();
        Cursor groupCur = cr.query(
                Groups.CONTENT_URI, // what table/content
                new String [] {Groups._ID, Groups.NAME},    // what columns
                "Groups.NAME NOT LIKE + 'System Group:%'", // where clause(s)
                null, // ???
                Groups.NAME + " ASC" // sort order
        );

我将其隔开以便更容易解释,但这是您通常看到的:

Cursor groupCur = cr.query(Groups.CONTENT_URI, null, null, null, null);

【讨论】:

    【解决方案2】:

    我找到了查询

    SELECT * FROM DATABASE_TABLE
        WHERE strftime('%Y-%m-%d',DATE) >= date('now','-6 days') AND 
        strftime('%Y-%m-%d',DATE)<=date('now') order by DATE
    

    【讨论】:

      猜你喜欢
      • 2011-12-28
      • 1970-01-01
      • 2021-12-17
      • 2011-06-26
      • 2014-10-31
      • 2020-05-20
      • 1970-01-01
      • 2012-07-13
      • 2021-01-04
      相关资源
      最近更新 更多