一、问题描述:
Mysql排序时如果用的的字段为字符串型的,排序规则是这样的:如1,10,2,20,3,4,5,这种排序是按照字符从第一个字符开始比较出来的,但不是我想要的,我想要的是:1,2,3,4,5……,10,20这种。
二、解决方案
排序时,把相应的字段转换成整型,使用CAST函数,如下:
CAST(seat_row AS UNSIGNED)
完整例子:
SELECT * FROM ts_seat WHERE hall_id =840 ORDER BY CAST(seat_row AS UNSIGNED) ,CAST(seat_col AS UNSIGNED);
转自https://blog.csdn.net/w995223851/article/details/88350024
标签:10,20,seat,CAST,字符串,排序
From: https://www.cnblogs.com/zhangzaizz/p/16612936.html