SQL for ordering by number - 1,2,3,4 etc instead of 1,10,11,12

前端 未结 8 2315
清歌不尽
清歌不尽 2020-11-30 19:13

I’m attempting to order by a number column in my database which has values 1-999

When I use

ORDER_BY registration_no ASC

I get….

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 19:58

    ORDER_BY cast(registration_no as unsigned) ASC
    

    gives the desired result with warnings.

    Hence, better to go for

    ORDER_BY registration_no + 0 ASC
    

    for a clean result without any SQL warnings.

提交回复
热议问题