![](/img/trans.png)
[英]python sqlite how to insert some data from one row into another table with additional data from code
[英]How to insert data from one table into another table?
我是python的新手,我试图将数据从一个表插入到另一个表中,并且代码正在执行,但是它没有反映我要在其中插入数据的新表中的任何更改。
import mysql.connector
conn=mysql.connector.connect(user='root',password='',host='localhost',database='xyz')
mycursor=conn.cursor()
mycursor.execute("insert into newTable select * from oldTable group by mac,date,time order by mac")
您需要添加commit()进行更改。
conn.commit()
我想这是因为您没有提交更改。 使用下面的代码,看看它是否有效。
conn.commit()
您需要使用conn,因为那是您与数据库连接的变量名。 必须将提交发送到服务器,然后服务器将提交您的更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.