0
 Cursor cursor = db.rawQuery("SELECT id,lastname,status FROM people WHERE " + "id = "+ IncomingiD +" FROM people WHERE status =100 ); ",null);

我想访问我的人员表的“status=100 和 id=incomingid”。我在上面编写了代码片段,但在下面出现错误......该查询有什么问题?请你帮助我好吗 ?

E/Error(996): Error while openining peopleandroid.database.sqlite.SQLiteException: near "FROM": syntax error: , while compiling: SELECT id,lastname,status FROM people WHERE  id = 1 FROM places WHERE status =100 ); 
4

3 回答 3

1

FROM people您的查询中有两次该部分:

  • 首先,在正确的位置,在 select 和 where 子句之间
  • 然后,第二次,在 where 子句中的第一个条件之后。

另外,请注意,您where的查询中有两次——这两个条件应该用 and 分隔and,而不是 second where

哦,您的查询结束时似乎也有一个结束)


基本上,您的查询如下所示:

SELECT id,lastname,status 
FROM people 
WHERE id = ....
FROM people 
WHERE status =100 
); 

但它应该是这样的:

SELECT id,lastname,status 
FROM people 
WHERE id = ....
    and status = 100 


最后,我猜你的 Java 代码应该看起来像这样:

Cursor cursor = db.rawQuery("SELECT id, lastname, status FROM people WHERE id = " + IncomingiD + " AND status = 100",null);
于 2012-05-19T20:30:43.050 回答
0

查询应为

 Cursor cursor = db.rawQuery("SELECT id,lastname,status FROM people WHERE " + "id = "+ IncomingiD +"AND status =100 ); ",null);
于 2012-05-19T20:30:18.130 回答
0

你的查询是错误的。sql语句中只能有一个FROM。

尝试这个:

cursor = db.rawQuery("SELECT id,lastname,status FROM people WHERE " + "id = "+ IncomingiD +" AND status =100 ); ",null);
于 2012-05-19T20:31:00.960 回答