我在MySQL中有一个表,其中包含505行的数字列表
1 2 3 4
------------------
A | 16 23 30 10
B 8 56 67 1
我试图将每列除以最后一列,然后将结果存入类似格式的表中。我对如何增加它有点迷茫。我的代码看起来像这样。
cursor.execute("select * from 'database'.'count'"
" where name =%s;", name)
logs = cursor.fetchall()
cursor.execute("INSERT INTO `database`.`averages`(`name`) "
"VALUES (%s) ON DUPLICATE KEY UPDATE "
"`1`=0, `2`=0, `3`=0, `4`=0, `5`=0, `6`=0,"
" `7`=0, `8`=0, `9`=0, `10`=0, `>10`=0,`-1`=0, `-2`=0, "
"`-3`=0, `-4`=0, `-5`=0, `-6`=0, `-7`=0, `-8`=0, "
"`-9`=0, `-10`=0, `<-10`=0;", name)
con.commit()
logs = [list (y) for y in logs]
从那里我在格式化代码的最佳方法上画了一个空白,想到某种for循环,但有更好的方法。