我想从android的sqlite数据库的列中获取总和和平均值。 搜索我发现了很多方法,我尝试了他们不成功。
要获取值的数量,我使用的列:
cursor.getCount() // with the cursor in the right column
和它的作品。我的问题是如何获得总和。 这是我“建”的方法:
public void setValues()
{
SQLiteDatabase db = mDbHelper.getReadableDatabase();
String[] projection = {
_ID,
DiabeticContract.DiabeticEntry.COLUMN_GLYCAEMIA_VALUES,
};
Cursor curs = db.query(
DiabeticContract.DiabeticEntry.TABLE_NAME,
projection,
null,
null,
null,
null,
null);
curs.moveToLast();
double lastGlycValue = curs.getDouble(curs.getColumnIndex("Glycaemia"));
double percent = (lastGlycValue + 46.7)/28.7;
double mmol = ((percent - 2.15) * 10.929);
LastGlyc.setText(String.format("%.2f" ,lastGlycValue));
Percent.setText(String.format("%.2f" ,percent));
mMol.setText(String.format("%.2f" ,mmol));
}
这是不cursor.getCount(),以使其更清晰。
谢谢你的帮助。
2017-02-26
Mark.
+0
你为什么不使用SQL查询数据? –
+0
我还使用内容提供商更好地处理数据 –