从一个 table 插入选定的字段到另一个后,如何 insert/update 新记录?

After inserted selected fields from one table to another, how to insert/update new records?

我可以使用 INSERT INTO Table B(planid, testno, sd, testname) VALUES (%s, %s, %s, %s);SQL = "select * from Table A"cursor.execute(SQL) 插入从 Table A 到 Table B 的选定字段,但是 table A随时都会有新记录,如何插入新记录和更新旧记录?非常感谢任何建议。

----首先更新现有记录:

更新表b set testno=t2.testno, sd=t2.sd, testname=t2.testname 从 tableb t1 inner join tablea t2 where t1.planid=t2.planid

----插入新记录 插入表b select * 来自 tablea,其中 planid 不在(select 来自 tableb 的 planid)