2016-05-29 64 views
0

我想用不同的值更新多行。用不同的值更新多行python和mysql

例如我的表是:

ID |名称|数据

1 | ahmad |年2015

2 | ali | 2014年

我希望我的表看起来像这样:

ID |名称|数据|号码

1 | ahmad | 2015年| 2

2 | ali | 2014年| 3

有超过7000行我不能一一填写。

我试图在Python这样做的查询是:

#words count in a tweet 
    words= processedRow.split() 
    fdist2=len(words) 

    for val in cursor.fetchall(): 
     cursor.execute("""UPDATE TWEETER1 SET t1=%s where id = %s""",(fdist2,val)) 
     db.commit() 

请帮助我做我的工作。谢谢

回答

0

是的,你可以。 7000是计算机的低端产品。

您可以尝试优化> 100k以使用多个数据库连接,或者不要在每次更新时提交,但这超出了您的问题范围。

+0

你能帮我查询吗? – SmartF