sqlite SQLlite3根据Where条件向列中插入值

1hdlvixo  于 2022-12-13  发布在  SQLite
关注(0)|答案(1)|浏览(178)

我尝试只在满足特定where条件的行(当Name列中的值等于给定名称时)的新列中插入值。
这是我目前编写的代码:

cours.execute("""INSERT INTO NewTable(Straight, Right, Left) WHERE Name = (?)
                                    VALUES (?, ?, ?) """,
                  (name, DIRECTIONS['straight'], DIRECTIONS['right'], DIRECTIONS['left']))
    conn.commit()

在我提交之后,我得到以下错误:
sqlite3.OperationalError:“地点”附近:语法错误

  • 谢谢-谢谢
blpfk2vs

blpfk2vs1#

尝试使用UPDATE语句:

cours.execute("""UPDATE NewTable 
                 SET Straight = ?, Right = ?, Left = ? 
                 WHERE Name = ?""", 
              (DIRECTIONS['straight'], DIRECTIONS['right'], DIRECTIONS['left'], name))

相关问题