四季花海
人们用不同的技巧来做这件事。我在谷歌上搜索并发现了一些结果,每个结果都遵循不同的技巧。看看他们:MySQL中的α数字排序MySQL中的自然排序混合字母数字值的数值排序MySQL自然排序MySQL中的自然排序编辑:我刚刚为未来的访问者添加了每个链接的代码。MySQL中的α数字排序给定输入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_columnFROM db_tableORDER BY binray_not_needed_column ASC , tbl_column ASC-----------------------Cast Way===================================SELECT tbl_column, CAST(tbl_column as SIGNED) AS casted_columnFROM db_tableORDER BY casted_column ASC , tbl_column ASCMySQL中的自然排序给定输入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;希望这能帮上忙
SMILET
就这么做吧:SELECT * FROM table ORDER BY column `name`+0 ASC附加+0将意味着:0, 10, 11, 2, 3, 4变成:0, 2, 3, 4, 10, 11