MySql 字段排序

发布网友 发布时间:2022-04-22 02:15

我来回答

2个回答

热心网友 时间:2022-04-08 04:11

select *
from sellrecord
order by convert(int,substring(listnumber,1,2)) asc,convert (int,substring(listnumber,4,len(listnumber)-2)) asc

热心网友 时间:2022-04-08 05:29

mysql> SELECT
-> ListNumber,
-> SUBSTRING_INDEX(ListNumber,'-',1) A,
-> SUBSTRING_INDEX(ListNumber,'-',-1) B
-> FROM
-> SellRecord
-> ORDER BY
-> CAST(SUBSTRING_INDEX(ListNumber,'-',1) as SIGNED),
-> CAST(SUBSTRING_INDEX(ListNumber,'-', -1) as SIGNED);
+------------+------+------+
| ListNumber | A | B |
+------------+------+------+
| 13-1 | 13 | 1 |
| 13-2 | 13 | 2 |
| 13-3 | 13 | 3 |
| 13-10 | 13 | 10 |
| 13-11 | 13 | 11 |
| 13-15 | 13 | 15 |
| 13-18 | 13 | 18 |
| 13-100 | 13 | 100 |
| 13-108 | 13 | 108 |
| 14-1 | 14 | 1 |
| 14-2 | 14 | 2 |
+------------+------+------+
11 rows in set (0.00 sec)

mysql>

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com