How do i order my SQLITE database in descending order, for an android app?

后端 未结 11 1577
死守一世寂寞
死守一世寂寞 2020-11-27 16:44

What is the most efficient method of showing my data in descending order?

public String getRank() {

    String[] rank = new String[]{ KEY_ROWID };
    Curso         


        
相关标签:
11条回答
  • 2020-11-27 17:33
    Cursor c = scoreDb.query(Table_Name, score, null, null, null, null, Column+" DESC");
    

    Try this

    0 讨论(0)
  • 2020-11-27 17:35

    This a terrible thing! It costs my a few hours! this is my table rows :

    private String USER_ID = "user_id";
    private String REMEMBER_UN = "remember_un";
    private String REMEMBER_PWD = "remember_pwd";
    private String HEAD_URL = "head_url";
    private String USER_NAME = "user_name";
    private String USER_PPU = "user_ppu";
    private String CURRENT_TIME = "current_time";
    
    Cursor c = db.rawQuery("SELECT * FROM " + TABLE +" ORDER BY " + CURRENT_TIME + " DESC",null);
    

    Every time when I update the table , I will update the CURRENT_TIME for sort. But I found that it is not work.The result is not sorted what I want. Finally, I found that, the column "current_time" is the default row of sqlite.

    The solution is, rename the column "cur_time" instead of "current_time".

    0 讨论(0)
  • 2020-11-27 17:37

    Query has two syntax, the syntax you are using, last column represents orderBy, you just need to specify on what column you want to do orderBy +"ASC" (or) orderBy +"DESC"

    Cursor c = scoreDb.query(DATABASE_TABLE, rank, null, null, null, null, yourColumn+" DESC"); 
    

    Refer this documentation to understand more about query() method.

    0 讨论(0)
  • 2020-11-27 17:38

    you can do it with this

    Cursor cursor = database.query(
                TABLE_NAME,
                YOUR_COLUMNS, null, null, null, null, COLUMN_INTEREST+" DESC");
    
    0 讨论(0)
  • 2020-11-27 17:38

    SQLite ORDER BY clause is used to sort the data in an ascending or descending order, based on one or more columns. Cursor c = scoreDb.query(DATABASE_TABLE, rank, null, null, null, null, yourColumn+" DESC");

    SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.query(
                TABLE_NAME,
                rank,
                null,
                null,
                null,
                null,
                COLUMN + " DESC",
                null);
    
    0 讨论(0)
提交回复
热议问题