如何在sqlite IPHONE中获取rowNum like列 [英] how to get rowNum like column in sqlite IPHONE
问题描述
我有一个像这样的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 强> ......
但是要限制为0-5 5-10 .... **它可以使用rowid,因为它们是混乱的顺序
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中没有像列一样的颜色
Note: WE DONTE HAVE ROWNUM LIKE COLUMN IN SQLITE
推荐答案
这是伪造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 like列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!