SQlite Group by子句

时间:2012-12-07 07:40:30

标签: android sqlite

我在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;
}

0 个答案:

没有答案