cur.execute("UPDATE statdata(threemonthreturn, twomonthreturn, maxonemonthreturn, avgonemonthreturn, lastweekreutrn) values (?, ?, ?, ?, ?) WHERE companyid=%s; ", (str(threemonthreturn), str(twomonthreturn), str(maxonemonthreturn), str(avgonemonthreturn), str(lastweekreturn)) %p)
我遇到这行代码时遇到了困难。一切正常,除了companyid =%s和%p。我收到此错误: TypeError:%:' tuple'不支持的操作数类型和' int'
我有一个循环,其中p在范围内(1,72):'我已经在之前的几行代码中使用它而没有任何问题。 (以下示例不会返回错误)
for p in range(1,72):
cur.execute("SELECT (((onemonthmax - threemonthmin) / (onemonthmax))*100) FROM statdata WHERE companyid = %s" %p)
threemonthreturn =cur.fetchone()[0]
有人可以帮助我在我发布的第一行代码中放置companyid =%s,%p。
答案 0 :(得分:0)
试试这个:
cur.execute("UPDATE statdata(threemonthreturn, twomonthreturn, maxonemonthreturn, avgonemonthreturn, lastweekreutrn) values (?, ?, ?, ?, ?) WHERE companyid=?; ", (str(threemonthreturn), str(twomonthreturn), str(maxonemonthreturn), str(avgonemonthreturn), str(lastweekreturn), p))
execute
的第二个参数是元组:sqlite3 docs