Saturday, 15 March 2014

android - First digit only descending -



android - First digit only descending -

i coudn't imagine why score not descending. first digit sort. help me guys analyze code , tell me whats wrong answer.

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"; } homecoming result; }

the problem key_score beingness stored string , not number.

there more 1 way prepare this. cast score integer or float:

cast(key_score float) desc

or, if integer no leading 0s, next trick works:

len(key_score) desc, key_score desc

however, in databases len() function might spelled length() or else.

android sql database

No comments:

Post a Comment