开发者

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 year

I created a data base table using SQLite in my project, I want to retrieve records from the database for the last week, for the last month, for the last year, when user click on the specified Buttons. But I don't know h开发者_开发知识库ow to retrieve the records. Is there any function exist to get these records accordingly ?


You'll need to construct a "where" clause like so:

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
        );

I spaced this out so it's easier to explain, but this is what you typically see as:

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


I found the query

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜