3 回答
TA贡献1874条经验 获得超12个赞
给定输入
1A 1a 10A 9B 21C 1C 1D
预期产出
1A 1C 1D 1a 9B 10A 21C
查询
Bin Way
===================================
SELECT
tbl_column,
BIN(tbl_column) AS binray_not_needed_column
FROM db_table
ORDER BY binray_not_needed_column ASC , tbl_column ASC
-----------------------
Cast Way
===================================
SELECT
tbl_column,
CAST(tbl_column as SIGNED) AS casted_column
FROM db_table
ORDER BY casted_column ASC , tbl_column ASC
给定输入
Table: sorting_test
-------------------------- -------------
| alphanumeric VARCHAR(75) | integer INT |
-------------------------- -------------
| test1 | 1 |
| test12 | 2 |
| test13 | 3 |
| test2 | 4 |
| test3 | 5 |
-------------------------- -------------
预期产出
-------------------------- -------------
| alphanumeric VARCHAR(75) | integer INT |
-------------------------- -------------
| test1 | 1 |
| test2 | 4 |
| test3 | 5 |
| test12 | 2 |
| test13 | 3 |
-------------------------- -------------
查询
SELECT alphanumeric, integer FROM sorting_test ORDER BY LENGTH(alphanumeric), alphanumeric
给定输入
2a, 12, 5b, 5a, 10, 11, 1, 4b
预期产出
1, 2a, 4b, 5a, 5b, 10, 11, 12
查询
SELECT versionFROM version_sortingORDER BY CAST(version AS UNSIGNED), version;
TA贡献1798条经验 获得超3个赞
SELECT * FROM table ORDER BY column `name`+0 ASC
0, 10, 11, 2, 3, 4
0, 2, 3, 4, 10, 11
添加回答
举报