我创建了一个有8列的表,我只想插入小于列号的值。我怎样才能做到这一点?一个答案将不胜感激。
logback.xml
答案 0 :(得分:0)
您应该能够只在VALUES
子句中指定要为其提供数据的列:
INSERT INTO tb_transaction (empID, time_in_morning, time_out_morning)
VALUES (?, ?, ?)
您的Python代码:
c.execute("""INSERT INTO tb_transaction (empID, time_in_morning, time_out_morning) VALUES (:empID, :time_in_morning, :time_out_morning)""")
以上内容可能不适用于SQLite(尽管它当然适用于MySQL)。您可以尝试的一种解决方法是使用占位符进行INSERT INTO ... SELECT
:
INSERT INTO tb_transaction (empID, time_in_morning, time_out_morning)
SELECT ?, ?, ?;
这是该代码的Python代码:
c.execute("""INSERT INTO tb_transaction (empID, time_in_morning, time_out_morning) SELECT :empID, :time_in_morning, :time_out_morning""")