SQLite ORDER BY string containing number starting with 0

后端 未结 5 2131
小蘑菇
小蘑菇 2020-12-13 06:44

as the title states:

I have a select query, which I\'m trying to \"order by\" a field which contains numbers, the thing is this numbers are really strings starting w

5条回答
  •  粉色の甜心
    2020-12-13 07:29

    Thanks to Skinnynerd. with Kotlin, CAST worked as follows: CAST fix the problems of prioritizing 9 over 10 OR 22 over 206.

    define global variable to alter later on demand, and then plug it in the query:

    var SortOrder:String?=null
    

    to alter the order use:

    For descendant:

     SortOrder = "CAST(MyNumber AS INTEGER)" + " DESC"
    

    (from highest to lowest)

    For ascending:

     SortOrder =  "CAST(MyNumber AS INTEGER)" + " ASC"
    

    (from lowest to highest)

提交回复
热议问题