0

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

这是我的代码,请告诉我,我哪里出错了:

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());
        }
    }
4

1 回答 1

0

使用下面的代码它将起作用:

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());
       }
   }
于 2013-11-14T11:17:21.720 回答