简体   繁体   中英

how row Max record database sqlite in android

i want show Max record in database sqlite in android But there is an error? Please help me

 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;

}

Probably the error is thrown because in your results there is no column with name day .
You must alias the aggregated column MAX(day) to day :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM