我正在尝试创建一个名为stock的表,用于跟踪某人在购买了一定数量的股票后拥有多少股票。这是迄今为止我尝试过的最复杂的sql代码,我想我写错了什么。有人能发现错误吗?
db.execute("IF EXISTS (SELECT * FROM stock WHERE symbol = :symbol AND userid = :userid)
UPDATE stock SET (amount = amount + 1) WHERE userid = :userid
ELSE INSERT INTO stock (userid, symbol, amount)
VALUES ((SELECT id FROM users WHERE id = :userid),
:symbol, :amount", userid = session["user_id"], symbol = symbol, amount = share_number)
1条答案
按热度按时间6ioyuze21#
之后缺少一个括号
而不是
(SELECT id FROM users WHERE id = :userid)
你可以简单地写