加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-12 19:18:16 所属栏目:百科 来源:网络整理
导读:什么是以降序显示我的数据的最有效的方法? 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.getC
什么是以降序显示我的数据的最有效的方法?
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文档了解更多关于查询方法。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读