UPDATE tbl_users
SET cash = SUM(cash + (SELECT reward FROM tbl_missions WHERE id = 1))
WHERE id = 1
LIMIT 1
这是我的查询。它不起作用,我搜索网络时找不到任何东西。我该如何解决?
谢谢!
答案 0 :(得分:1)
我假设你正在尝试进行更新加入:
UPDATE `tbl_users` u
JOIN (SELECT id, SUM(`reward`) AS reward_total
FROM `tbl_missions` m
GROUP BY id) ON u.id = m.id
SET `cash` = `cash` + m.reward_total
WHERE `id` = 1
答案 1 :(得分:1)
那不就是:
UPDATE `tbl_users`
SET `cash` = `cash` + (SELECT `reward` FROM `tbl_missions` WHERE `id` = 1)
WHERE `id` = 1
LIMIT 1
...除非我在你的问题中遗漏了什么,否则我认为这就是你要找的东西。