我有一个专栏:
1 TB
1.5 TB
2 TB
3 TB
16 GB
32 GB
64 GB
128 GB
256 GB
320 GB
500 GB
512 GB
750 GB
我希望 1 TB、1.5 TB、2 TB 和 3 TB 出现在最后。
如何做到这一点?
最佳答案
假设您只有 TB
和 GB
:
order by (case when col like '%GB' then 1
when col like '%TB' then 2
end),
col + 0 asc
这按 GB 排序。第二个将列转换为数字并按数字排序。
关于Mysql自然顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23976188/