行最大如何在Android中记录数据库sqlite

时间:2019-04-30 14:53:23

标签: android sql sqlite

我想在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;

}

1 个答案:

答案 0 :(得分:0)

可能会引发错误,因为结果中没有名称为day的列。
您必须将聚合列MAX(day)别名为day

SELECT did,MAX(day) day,hazine FROM Day