我很难使用MySQLdb模块将信息插入到我的数据库中。我需要在表中插入2个变量。我的表是userid,user_id的类型是 varchar ,计数的类型是 int 。
SQL = 'select user_id,count(*)AS num from client1 group by user_id order by count(*) desc;'
for row in cursor.execute(SQL):
a = row.user_id
b = row.num
cursormysql.execute("insert into userid(user_id,count) VALUES (%s,%s))",(a,b))
db.commit()
答案 0 :(得分:1)
您的括号与之匹配
cursormysql.execute("insert into userid(user_id,count) VALUES (%s,%s))",(a,b))
尝试cursormysql.execute("insert into userid(user_id,count) VALUES (%s,%s)",(a,b))