查询SQLite数据库特定/自定义排序? [英] Query Sqlite Database by specific/custom ordering?

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

问题描述

比方说,我有一个表,是这样的:

Let's say I got a table, something like this:

ID |标题结果
1 | AAA结果
2 | BBB结果
3 | CCC结果
4 | DDD结果
5 | EEE结果
...结果
...

ID | TITLE
1 | AAA
2 | BBB
3 | CCC
4 | DDD
5 | EEE
...
...

我想执行一个查询,使用IN opeator,而preserving的IN参数的顺序

I want to perform a query, using IN opeator, while preserving the order of the IN Arguments

database.query("some_table", null, ID + " IN("+ idsStr+")", null, null, null, null);

例如,如果查询的是,我想返回的光标进行排序为4,1,从some_table其中id在(4,1,5)...(由???顺序)选择 5

For example, if the query is "select from some_table where id in (4,1,5) ...(order by???)", I want that the returned cursor to be sorted as 4,1,5

这可能吗?怎么样?

推荐答案

编辑:

测试,如下:

SELECT * FROM books WHERE _id IN(4, 1, 5) 
ORDER BY
CASE _id
WHEN '4' THEN 1
WHEN '1' THEN 2
WHEN '5' THEN 3
ELSE 4
END, _id;

这篇关于查询SQLite数据库特定/自定义排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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