简体   繁体   中英

How to order sqlite table according to accending integer?

I am having some problems with ORDER BY in android sqlite.

I am using this query to reorder my listview :

Select * From tbl_name ORDER BY WithOrder asc

Where WithOrder is an Integer type column. The expected behavior I was hoping for was that sqlite will reorder the rows as ....8,9,10,11,12.... but it is reordering the list according to the first digit instead as ....10,11,8,9....

Please help me with reordering the table with ascending values of integer...I can not opt for any other column or datatype to reorder as I depend heavily on WithOrder for general calculations when the user reorders the list.

Thanks!

Parvaz Bhaskar

While numbers are sorted according to their numerical value, strings are sorted lexicographically, beginning with the first character. In particular, the character 1 is less than the character 8 , so any string beginning with 1 (such as 11 ) is sorted before any string beginning with 8 .

Recreate your table so that the WithOrder column has type INTEGER .

Cursor c =  SQLiteDatabase_OBJ.query("Table_name", null, null, null, null, null, "WithOrder ASC");

尝试这个

试试这个ORDER BY CAST(WithOrder AS INTEGER) ASC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM