gpt4 book ai didi

sql用子选择更新多行

转载 作者:行者123 更新时间:2023-12-04 13:53:00 25 4
gpt4 key购买 nike

我正在尝试将 Gradation_term 表中相应的graduate_date 值复制到 user_education_mba_school 表中具有匹配gradation_term_id 的行中。这是我的非工作查询

TABLE DEFS
**user_education_mba_school
school_id
graduation_date
graduation_term_id

**graduation_term
graduation_term_id
graduation_year_id
graduation_date

**graduation_class
graduation_class_id
graduation_year_id

**user
user_id
graduation_class_id

-- 多连接不工作...
UPDATE  u
SET graduation_class_id = gc.graduation_class_id
FROM [user] u
JOIN user_education_mba_school mba
ON mba.user_id = u.user_id
JOIN graduation_term gt
ON mba.graduation_term_id = gt.graduation_term_id
JOIN graduation_class gc
ON gt.graduation_year_id = gc.graduation_year_id

最佳答案

多个数据库支持 update ... from语法,这是相当清楚的:

UPDATE  mba
SET graduation_date = gt.graduation_date
FROM user_education_mba_school mba
JOIN graduation_term gt
ON gt.graduation_term_id = mba.graduation_term_id

如果您的数据库没有,请说明您使用的是哪个数据库。

关于sql用子选择更新多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11254669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com