-1

我无法想象为什么我的分数没有下降。这是仅排序的第一个数字。帮我分析这段代码并告诉我什么是错的还有答案。

   public String getData() {    
   Cursor c= ourDatabase.query(DATABASE_TABLE, new String[] {KEY_NAME, KEY_SCORE},  
null, null, null, null, KEY_SCORE +" DESC");
   String result = "";


int iname = c.getColumnIndex(KEY_NAME);
int iscore = c.getColumnIndex(KEY_SCORE);

for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
    result = result +  c.getString(iname) + "    "+   c.getInt(iscore)+ "\n";

 }

 return result;

 }
4

1 回答 1

1

The problem is probably that KEY_SCORE is being stored as a string and not as a number.

There is more than one way to fix this. Cast the score to an integer or float:

cast(Key_Score as float) desc

Or, if it is an integer with no leading 0s, the following trick works:

len(Key_Score) desc, key_score desc

However, in some databases the len() function might be spelled length() or something else.

于 2013-02-20T15:53:30.903 回答