如何为我的SQLITE数据库按降序排序,Android应用程序?

前端之家收集整理的这篇文章主要介绍了如何为我的SQLITE数据库按降序排序,Android应用程序?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
什么是以降序显示我的数据的最有效的方法
public String getRank() {

    String[] rank = new String[]{ KEY_ROWID };
    Cursor c = scoreDb.query(DATABASE_TABLE,rank,null,null);   //reading information from db.
    String rankResult = "";

    int iRow = c.getColumnIndex(KEY_ROWID); //Cursor looking for column setting equal to these ints.


    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { 
        //Move to first row - where cursor starts and moves to next row as long it is not after last row.
        rankResult = rankResult + c.getString(iRow) + "\n"; 
        //Returning value of row that it is currently on.
    }
    return rankResult;  //returning result
}

public String getName() {

    String[] name = new String[]{ KEY_NAME };
    Cursor c = scoreDb.query(DATABASE_TABLE,name,null);   //reading information from db.
    String nameResult = "";

    int iRow1 = c.getColumnIndex(KEY_NAME); //Cursor looking for column setting equal to these ints.


    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { 
        //Move to first row - where cursor starts and moves to next row as long it is not after last row.
        nameResult = nameResult + c.getString(iRow1) + "\n"; 
        //Returning value of row that it is currently on.
    }
    return nameResult;  //returning result
}

public String getscore() {

    String[] score = new String[]{ KEY_score };
    Cursor c = scoreDb.query(DATABASE_TABLE,score,null);   //reading information from db.
    String scoreResult = "";

    int iRow2 = c.getColumnIndex(KEY_score); //Cursor looking for column setting equal to these ints.


    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { 
        //Move to first row - where cursor starts and moves to next row as long it is not after last row.
        scoreResult = scoreResult + c.getString(iRow2) + "\n"; 
        //Returning value of row that it is currently on.
    }
    return scoreResult; //returning result
}
查询有两种语法,你使用的语法,最后一列代表顺序,你只需要指定你要做什么列order by“ASC”(或)orderby“DESC”
Cursor c = scoreDb.query(DATABASE_TABLE,yourColumn+" DESC");

参考this文档了解更多关于查询方法

猜你在找的Sqlite相关文章