我正在使用SUGAR ORM
,我想做“值”列的总和,但遇到此错误。
请帮助。
String whereCondition ="Select unique_id, name, Sum(value), type, category_type, note, nutrient_code from NUTRIENTS group by unique_id";
List<Nutrients> nutrientsList = Nutrients.findWithQuery(Nutrients.class, whereCondition);
答案 0 :(得分:0)
Sum(value)不能直接与SugarORM一起使用。为此,我们需要使用如下的SQL原始查询:
String whereCondition ="Select unique_id, name, Sum(value), type, category_type, note, nutrient_code from NUTRIENTS group by unique_id";
Field f = null;
try {
f = SugarContext.getSugarContext().getClass().getDeclaredField("sugarDb");
f.setAccessible(true);
SugarDb db = (SugarDb) f.get(SugarContext.getSugarContext());
Cursor cursor = db.getDB().
rawQuery(whereCondition, null);