我想在Android的数据库sqlite中显示Max记录 但是有错误吗? 请帮助我
public Day show_Day_Hazine_Max()
{
SQLiteDatabase database=getReadableDatabase();
Cursor cursor=database.rawQuery("SELECT did,MAX(day),hazine FROM Day",null);
if(cursor == null)
{
return null;
}
cursor.moveToFirst() ;
Day day = new Day();
day.setDid(cursor.getInt(cursor.getColumnIndex("did")));
day.setDay(cursor.getInt(cursor.getColumnIndex("day")));
day.setHazine(cursor.getInt(cursor.getColumnIndex("hazine")));
cursor.close();
database.close();
return day;
}
答案 0 :(得分:0)
可能会引发错误,因为结果中没有名称为day
的列。
您必须将聚合列MAX(day)
别名为day
:
SELECT did,MAX(day) day,hazine FROM Day