![](/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.