我有 2 张桌子;一个是用户,另一个记录用户操作。我想计算每个用户的操作数并将其记录在用户表中。大约有 10 万用户,下面的代码需要 6 个小时!一定会有更好的办法!
def 计算邀请():
sql_db.execute("SELECT id, uid FROM users")
for row in sql_db:
id = row['id']
uid = row['uid']
sql1 = "SELECT COUNT(1) FROM actions WHERE uid = %s"
sql_db.execute(sql1, uid)
count_actions = sql_db.fetchone()["COUNT(1)"]
sql = "UPDATE users SET count_actions=%s WHERE uid=%s"
sql_db.execute(sql, (count_actions, uid))