我正在尝试通过从较高到较低的值获取记录来进行排序,但是排序没有发生,我是在随机获取记录。

这是我的代码,请让我知道我要去哪里了:

public void fetchTopRecords() {

    int i = 0;

     String where = "SELECT * FROM " + DATABASE_TABLE_2 + " ORDER BY "
     + COL_C + " ASC LIMIT 6";
     Cursor c = db.rawQuery(where, null);
    if (c != null) {
        if (c.moveToFirst()) {
            do {
                String pckname = c.getString(COL_A);
                array_pck.add(pckname);
                int marks = c.getInt(COL_C);
                i++;
            } while (c.moveToNext());
        }
    }

最佳答案

使用以下代码,它将起作用:

public void fetchTopRecords() {
   String where = "SELECT * FROM " + DATABASE_TABLE_2 + " ORDER BY "
    + COL_C + " DESC LIMIT 6";
   Cursor c = db.rawQuery(where, null);
   if (c != null) {
       if (c.moveToFirst()) {
          do {
             String pckname = c.getString(COL_A);
             array_pck.add(pckname);
             int marks = c.getInt(COL_C);
          } while (c.moveToNext());
       }
   }

07-24 09:48
查看更多