ORDER BY Month,Year DESC在SQLite中不起作用

时间:2016-07-11 05:22:21

标签: android sqlite

我有table日期字段,我将其转换为(3个单独{{ 1}})。工作正常但是我需要按照降序顺序按月和年份排序结果。

这是我的查询: -

columns

它以降序显示,但仅与MonthPart一起显示,而不是YearPart和MonthPart。请帮忙。

1 个答案:

答案 0 :(得分:2)

我得到了答案: -

Cursor c = database.rawQuery(
    "select count(*) as TotalCount, tDate, " +
            "sum(case when type = '1' then Amount else 0 end) \"Income\", " +
            "sum(case when type = '2' then Amount else 0 end) \"Expenses\", " +
            "(sum(case when type = '1' then Amount else 0 end) - sum(case when type = '2' then Amount else 0 end)) \"Profit\", " +
            "strftime('%d', tDate) as DayPart, " +
            "strftime('%m', tDate) as MonthPart, " +
            "strftime('%Y', tDate) as YearPart " +
            "from library " +
            "group by MonthPart, YearPart ORDER BY date(tDate) DESC", 
    null
);
相关问题