gpt4 book ai didi

MySQL 降序在 Varchar 中不能正确短缩

转载 作者:行者123 更新时间:2023-11-30 00:27:27 27 4
gpt4 key购买 nike

我有一个表名测试。我必须对 Var-char 字段进行排序。但是当我尝试排序时,我得到了错误的输出。

我的 table -

enter image description here

我的查询 -

select * from testtable order by test DESC;

我的输出 -

enter image description here

我想要什么,。

test
G450
G145
G56
G45
G4
G3

请帮助我获得此输出。

最佳答案

如果您的格式始终是一个字母后跟一个整数,则一种简单的方法是:

order by length(test) desc, test desc

即先按长度排序,再按字段排序。

关于MySQL 降序在 Varchar 中不能正确短缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22759805/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com