我使用下面的代码来获取过去两个月的数据。

 public List<String> getDates() {
        SQLiteDatabase db       = this.getReadableDatabase();
        List<String>   dateList = new ArrayList<>();

        String query = "SELECT DISTINCT " + KEY_PROGRESSDATE + " FROM " + TABLE_ENTRY + " WHERE progressdate >= date('now','start of month','-1 month') AND progressdate < date('now','start of month') desc";

        Cursor c = db.rawQuery(query, null);
        if (c.getCount() > 0) {
            while (c.moveToNext()) {
                dateList.add(c.getString(0));
            }
        }
        return dateList;
    }

但是我收到了下面的错误信息。
原因:android.database.sqlite.sqliteexception:near“desc”:
语法错误(代码1):,编译时:选择Distinct ProgressDate
from entry where progressdate>=日期('now','start of month','-1
月)和progressDate为什么会这样?

最佳答案

对于此异常,必须写入ORDER BY "Columname" DESC
在这里,就像

SELECT DISTINCT progressdate FROM entry WHERE progressdate >= date('now','start of month','-1 month') AND progressdate < date('now','start of month') ORDER BY progressdate desc

检查example here

10-08 18:10