我创建了一个表,它包含重复的值,如下所示:
id name mileage
1021 toyota 534
1021 toyota 783
1022 mazda 519
1023 nissan 559
在SQL中,我会成功执行:
SELECT id , SUM(mileage) as TotalMileage FROM vehicleTable group By id
我想知道如何使用greenDAO来做到这一点。这是我的代码
public List<Vehicles> LoadVehicleData() {
List<VehicleEntity> items = new ArrayList<>();
String sql = "SELECT * FROM vehicleTable ";
Cursor c = vehicleDao.getDatabase().rawQuery(sql, null);
while (c.moveToNext()) {
VehicleEntity ve = new VehicleEntity(
c.getLong(0),
new Date(),
mileage = c.getInt(2),
model = c.getString(3)
// break;
);
items.add(ve);
}
return items;
}