我想更新一个名为stock的表,其中product_id与另一个名为stock_in_temp
的表的product_id
匹配,并且名为crm_product_id
的列必须是null
或''
。
我试了这个代码:
conn.execute("UPDATE stock SET stock.quantity += stock_in_temp.quantity FROM stock, stock_in_temp WHERE stock.product_id = stock_in_temp.product_id AND stock_in_temp.CRM_product_id !='' ")
sqlite3.OperationalError: near ".": syntax error
1条答案
按热度按时间kjthegm61#
你的语法错误。
=
运算符左侧的更新列不能用表名限定。此外,
stock
不应在FROM
之后再次引用(这是一个逻辑错误,而不是语法错误),并且运算符+=
可能在编程语言中有效,但在SQLite中无效。变更为:
注意,如果
quantity
在stock
中是 * nullable *,则SET语句必须是:我使用别名而不是表名来缩短代码。