【发布时间】:2015-04-02 13:26:58
【问题描述】:
我环顾四周,发现了一些类似的案例,但没有一个需要对条目进行具体总结。所以我来了。
我有一个方法filterPayments,它根据特定的GroupID 返回我的PayTable 中的所有条目,然后显示在我的GridView 中。从那里我想总结PayTable 中5 列中的2 列的值,特别是我的Interest 和Due 列。我不确定如何在查询中执行此操作,更不用说仅针对特定列执行此操作了。
问题
如何添加特定列中所有条目的值。
是否可以在 SQLite 查询中执行此操作? 如果是如何使用filterPayments 的返回值并仅对特定列执行求和? 如果不是,那我该怎么做呢?
下面是我的代码 sn-ps。
filterPayments
Cursor filterPayments(String Payment) {
SQLiteDatabase db = this.getWritableDatabase();
String[] columns = new String[]{"_id", colGroupID, colPayBal, colInterest, colDue, colDateDue, colPaid};
Cursor c = db.query(viewPmnts, columns, colGroupID + "=?", new String[]{Payment}, null, null, null);
return c;
}
GridView
public void Paygrid() {
dbHelper = new DatabaseHelper(this);
String Payment = String.valueOf(txt.getText());
Cursor a = dbHelper.filterPayments(Payment);
startManagingCursor(a);
String[] from = new String[]{DatabaseHelper.colPayBal, DatabaseHelper.colInterest, DatabaseHelper.colDue, DatabaseHelper.colDateDue, DatabaseHelper.colPaid};
int[] to = new int[]{R.id.Amount, R.id.Interest, R.id.Due, R.id.DateDue, R.id.Paid};
SimpleCursorAdapter saa = new SimpleCursorAdapter(this, R.layout.paygrid, a, from, to);
intgrid.setAdapter(saa);
}
【问题讨论】: