SQLite的排序问题 [英] SQLite sorting question

查看:181
本文介绍了SQLite的排序问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SQLite数据库在我的Andr​​oid应用程序。

I'm using SQLite DB in my Android Application.

有一列中的数字和字符串。是这样的:

There are numbers and strings in a column. Something like:

3,1,2,6 / 6A中,X,3A,10,12,XY,44,ZW

3, 1, 2, 6 / 6A, X, 3A, 10, 12, XY, 44, ZW

如果我选择此列的值,并进行排序,我得到:

If I select values of this column and sort them, I get:

1,10,12,2,3,3A,44,6 / 6A中,X,XY,ZW

1, 10, 12, 2, 3, 3A, 44, 6 / 6A, X, XY, ZW

是否有任何可能的 SQLite的以这些值,以便进行排序,我会得到:

Is there any possibility in SQLite to sort these values so, that I would get:

1,2,3,3A,6 / 6A,10,12,44中,X,XY,ZW

1, 2, 3, 3A, 6 / 6A, 10, 12, 44, X, XY, ZW

感谢您,

穆尔

推荐答案

经过多次实验我已经有了一个正确的查询:

After many experiments I've got a proper query:

select _id, case 
when cast(_id as number) = 0 then _id
when cast(_id as number) <>0 then cast(_id as number)
end as sorting
from lines
order by sorting

的好处是,对于6 / 6A'6回铸造过程中的回报。

The good thing is, that the casting operation returns for '6 / 6A' 6 back.

UPD

不知道为什么,但如果我在Android应用程序使用此查询,我得到_id列数,所以我必须做铸件为文本

Don't know why, but if I use this query in my android application, I get _id column as number, so I must do the casting to text

select cast(_id as text) as _id, case 
when cast(_id as number) = 0 then _id
when cast(_id as number) <>0 then cast(_id as number)
end as sorting
from lines
order by sorting

这篇关于SQLite的排序问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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