使用sqlite对数字(和数字+字母)进行排序 [英] Sort numbers (and numbers+letters) with sqlite

查看:581
本文介绍了使用sqlite对数字(和数字+字母)进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Sqlite对VarChar字段进行排序.

I'm trying to sort a VarChar field with Sqlite.

该字段可以包含数字或数字+字母,但是我需要按数字顺序进行排序,如下所示:

The field can contain numbers or numbers+letters, but I need to sort in numerical order, like this:


1
1a
1b
5
5x
5y
10
10d
10e
10g1
11
11a
11b
100c
100f

有什么想法吗?我已经能够做到...接近(但不是完全)我需要的东西:

Any ideas? I've been able to do this... it is close (but not quite) what I need:

用'00000'填充字段的开头,然后在第1个5个字母上排序

Pad the start of the field with '00000', and then sort on the 1st five letters

推荐答案

简单

select col from tbl order by col*1, col

这篇关于使用sqlite对数字(和数字+字母)进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆