我有table
日期字段,我将其转换为月,年,日(3个单独{{ 1}})。工作正常但是我需要按照降序顺序按月和年份排序结果。
这是我的查询: -
columns
它以降序显示,但仅与MonthPart一起显示,而不是YearPart和MonthPart。请帮忙。
答案 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
);