import sqlite3
import numpy
conn = sqlite3.connect('lotto.db')
cur = conn.cursor()
def fun(a,b,c,d,e,f):
list = [a, b, c ,d, e, f]
print(list)
return numpy.mean(list)
numbers = cur.execute("SELECT * FROM combinations6")
numbers.fetchall()
for row in numbers:
cur.execute("UPDATE combinations6 WHERE id = ? SET average = ?", (row, fun(row[0],row[1],row[2],row[3],row[4],row[5]))
conn.commit()
conn.close()
在遍历每一行时遇到困难,得到语法错误,当它运行时,它只计算第一行的平均值并将其输入到数据库的所有行
让它迭代每一行并计算平均值并将其输入数据库,我做了什么错?在
对python还不熟悉,所以提前感谢您的帮助。在
问题不在Python中,而是与SQL语法有关。之后:
WHERE
子句位于^{别忘了交换替换参数的顺序来匹配这个。在
另外,您使用
row
作为id = ?
的参数,这是不对的。你不能把一个完整的列表放入一个参数中,它必须是列表的一个特定元素,例如row[6]
。我不知道ID列在表中的实际位置,所以我不知道正确的索引是什么。在您也可以使用单个查询完成整个操作:
^{pr2}$将
col1
等替换为计算平均值的列的实际名称。在奇怪地修复了添加到查询并使用不同的指针和不同的查询
^{pr2}$谢谢你的帮助,把我带到那里:)
相关问题 更多 >
编程相关推荐