问题描述
我有一个这样的 Sqlite 数据库表(没有升序)
I have an Sqlite database table like this (with out ascending)
但是我需要以按名称升序检索表,当我将其设置为升序时,rowId 会以混乱的顺序更改如下
But i need to retrive the table in Ascending order by name, when i set it ascending order the rowId changes as follows in jumbled order
但我每次都需要按升序检索一些数量有限的联系人 5
But i need to retrieve some limited number of contacts 5 in ascending order every time
喜欢Aaa - Eeee 和 然后是 Ffff- Jjjjj ......
like Aaa - Eeee and then Ffff- Jjjjj ......
但是要设置 **t 限制,例如 0-5 5-10 .... ** 它可以使用 rowids,因为它们处于混乱的顺序
but to se**t limits like 0-5 5-10 .... ** it can able using rowids since they are in jumble order
所以我需要另一列,如(oracle中的rowNum),其顺序为1234567...每次如下
如何使用现有列检索该列
how to retrive that column with existing columns
注意:我们在 SQLITE 中没有 ROWNUM LIKE COLUMN
推荐答案
这是一种伪造 RowNum 的方法,希望能帮到你:
This is a way of faking a RowNum, hope it helps:
SELECT
(SELECT COUNT(*)
FROM Names AS t2
WHERE t2.name < t1.name
) + (
SELECT COUNT(*)
FROM Names AS t3
WHERE t3.name = t1.name AND t3.id < t1.id
) AS rowNum,
id,
name
FROM Names t1
ORDER BY t1.name ASC
这篇关于如何在sqlite IPHONE中获取rowNum之类的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!