8

対応する卒業日の値を、graduation_term テーブルから user_education_mba_school テーブルの行にコピーしようとしています。ここに私の非稼働クエリがあります

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

-- マルチ JOIN が機能しない...

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
4

4 に答える 4

11

いくつかのデータベースが構文をサポートしてい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

データベースがそうでない場合は、使用しているデータベースを明確にしてください。

于 2012-06-29T00:29:02.793 に答える
3

サブクエリの結果セット全体を設定しているため、これは機能しません

UPDATE user_education_mba_school SET graduation_date = (
  SELECT gt.graduation_date
  FROM user_education_mba_school mba, graduation_term gt
  WHERE gt.graduation_term_id = mba.graduation_term_id
)

これは機能するはずです(テストされていません)

UPDATE user_education_mba_school mba SET graduation_date = (
  SELECT gt.graduation_date
  FROM graduation_term gt
  WHERE gt.graduation_term_id = mba.graduation_term_id
)
于 2012-06-29T00:29:36.593 に答える
0
UPDATE  mba
SET     graduation_date = gt.graduation_date, mba_graduation_year_id = gt.graduation_year_id
FROM    user_education_mba_school mba
JOIN    [sueldovista].dbo.graduation_term gt
ON      gt.graduation_term_id = mba.graduation_term_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    [sueldovista].dbo.graduation_term gt
ON      mba.graduation_term_id = gt.graduation_term_id
JOIN    [sueldovista].dbo.graduation_class gc
ON      gt.graduation_year_id = gc.graduation_year_id
WHERE   gc.site_instance_id = 1
于 2012-06-29T01:50:00.983 に答える
0

オラクル:

UPDATE PRODUCTION a
SET (name, count) = (
  SELECT name, count
  FROM STAGING b
  WHERE a.ID = b.ID);
于 2013-10-21T19:27:13.250 に答える