iPhone + sqlite3 +不在查询中

时间:2009-10-13 12:44:22

标签: iphone sqlite

我想在我的代码中编写查询。我的查询类似于:

SELECT  PlayerID, PlayerName, Type, BattingSkills, BallingSkills 
from Player 
where TeamId = 6 
      and PlayerID not in (163,174) 
order by battingSkills desc 
limit 4

在我的xCode中,我正在编写如下的查询

const char *sql = "SELECT  PlayerID, PlayerName, Type, BattingSkills, BallingSkills                                                                    from Player where TeamId = ? LIMIT 11";

sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) 
{
    sqlite3_bind_int(selectstmt, 1, teamId);
    ..................
    }

现在假设我想编写not in query(如上面的SQL查询),我将如何在xCode中编写代码以传递not in ID。

1 个答案:

答案 0 :(得分:2)

这可能有效(以与使用teamID相同的方式传递值):

const char *sql = "SELECT  PlayerID, PlayerName, Type, BattingSkills, BallingSkills from Player where TeamId = ? and playerID not in (?, ?) LIMIT 11";
...
sqlite3_bind_int(selectstmt, 1, teamId);
sqlite3_bind_int(selectstmt, 2, notID1);
sqlite3_bind_int(selectstmt, 3, notID2);