Mysql order number / character combined

夙愿已清 提交于 2019-12-11 09:35:22

问题


I have a SQL table with in a product-name field with the following values:

10b
 9b
 8b
 7b
 6b
 5b
 4b
 3b
 2b
 1b

These needs to be ordered from 1 to 10, but for some reason when i select with the following order: ORDER BY title ASC, then i get:

10b
1b
2b
3b
4b

etc..

But that 10 needs to be after the 9, not before the 1, how is this possible?

Thank you, Kind regards


回答1:


    SELECT 
          CAST(title AS UNSIGNED INTEGER) AS ORDER_FIELD
          ,title
    ORDER BY
          ORDER_FIELD ASC


来源:https://stackoverflow.com/questions/12601498/mysql-order-number-character-combined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!