Android加载到光标id范围

时间:2012-06-04 00:31:32

标签: android database sqlite

Cursor cursor = db.rawQuery("SELECT id,name FROM  people WHERE id="+ id + " AND name IS NULL",null); 

我不想只将一个id的记录加载到我的光标,而是想加载一系列id,例如将id = 100开始id = 150到光标。我怎样才能做到这一点 ?

4 个答案:

答案 0 :(得分:2)

您可以通过更改WHERE子句中使用的运算符来执行此操作。

SELECT id, name FROM  people WHERE id>100 AND id<150 AND name IS NULL

答案 1 :(得分:2)

尝试这些查询

SELECT id, name FROM  people WHERE id >= 100 AND id <= 150 AND name IS NULL
SELECT id, name FROM  people WHERE id BETWEEN 100 AND 150 AND name IS NULL

答案 2 :(得分:1)

Cursor cursor = db.rawQuery("SELECT id,name FROM  people WHERE id <"+ upperBoundId + " AND id > " + lowerBoundId" + AND name IS NULL",null);

答案 3 :(得分:0)

试试这个:

Cursor c = db.rawQuery("select id,name from people where id>100 and id<150 and name is null",null);
int Column1 = c.getColumnIndex("id");
int Column2 = c.getColumnIndex("name");
c.moveToFirst();
   if (c != null) {
    // Loop through all Results
    do {
         int id = c.getInt(Column1);
     String name = c.getString(Column2);

    }while(c.moveToNext());