mysql中按照字符串中数字顺序排序

开发中遇到的问题,需要按照字符串中数字进行排序

1.首先截取字符串中数字

2.将截取出的数字,强转为int类型的数字

3.按照数字排序

sql语句为:

1.先截取出BSS1,substring_index(s.sindex,':',1

2.在截取数字(substring(substring_index(s.sindex,':',1),4)

3.强转为cast(substring(substring_index(s.sindex,':',1),4) as unsigned )

4.排序

order by cast(substring(substring_index(s.sindex,':',1),4) as unsigned ) asc

注释:

不明白mysql字符串截取的,请参考上篇博文

http://blog.csdn.net/lxj_1993/article/details/79420847


猜你喜欢

转载自blog.csdn.net/lxj_1993/article/details/79421026