我在 android 中使用 sqlite 在 group by 子句中遇到问题。它只显示最后一条记录
这是我的数据库功能:
public List<Expense> getAllExpenses() {
List<Expense> ExpenseList = new ArrayList<Expense>();
// Select All Query
String selectQuery = "SELECT * FROM "+ ExpenseTable+" GROUP BY "+colCategoryId+"" ;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to ist
if (cursor.moveToFirst()) {
do {
Expense expense = new Expense();
expense.setItem_Desrp(cursor.getString(1));
expense.setPrice(Integer.parseInt((cursor.getString(2))));
expense.setDate(cursor.getString(3));
expense.setMode(cursor.getString(4));
expense.setCate_Id(Integer.parseInt(cursor.getString(5)));
// Adding expense to list
ExpenseList.add(expense);
} while (cursor.moveToNext());
}
return ExpenseList;
}