使用python脚本的mysql查询出错

时间:2011-04-01 18:33:17

标签: python mysql mysql-python

我已经编写了一条指令,使用2个id从数据库中获取频率,如下所示:

cursor = db.cursor()
cursor.execute("select freq from matrix_brown where a_id in (%s) and b_id in (%s)",b_item_id,b_after_id)
b_freq=cursor.fetchone()

但是我收到了这个错误:

cursor.execute("select freq from matrix_brown where a_id in (%s) and b_id in (%s)",b_before_id,b_item_id)
TypeError: execute() takes at most 3 arguments (4 given)

请帮帮我.. 谢谢.. :))

2 个答案:

答案 0 :(得分:1)

如果您希望execute填写字符串,则说错了:

cursor.execute("select freq from matrix_brown where a_id in (?) and b_id in (?)", (b_item_id,b_after_id))

答案 1 :(得分:0)

cursor.execute("select freq from matrix_brown where a_id in (%s) and b_id in (%s)",(b_item_id,b_after_id))