假设我有一个名为result
的子表。
SELECT school, grade
FROM (SELECT school, grade
FROM simulated_records
LIMIT 10) as result
我如何更新此子表的列?我试过了:
UPDATE result
SET grade = 'A'
...但我收到了错误。
答案 0 :(得分:2)
sub *选择*是临时的,它们无法更新。听起来你想要一个temporary table
CREATE TEMP TABLE temp_grades AS
SELECT school, grade FROM simulated_records;
UPDATE temp_grades SET grade = 'A';
编辑:你的评论:
UPDATE simulated_records
FROM (SELECT id FROM simulated_records WHERE school='Yale' LIMIT 10) AS result
SET grade='A'
WHERE id = result.id
RETURNING *;
以上使用子选择
的UPDATE FROM表操作编辑2:第二评论:
假设你没有拼写错误,也许你有旧版本。还有另一种方法可以提供更好的支持:
UPDATE simulated_records SET grade = 'A' WHERE id IN
(SELECT id FROM simulated_records WHERE school = 'Yale' LIMIT 10);