SQL update from one Table to another based on a ID match

后端 未结 22 1294
太阳男子
太阳男子 2020-11-21 22:49

I have a database with account numbers and card numbers. I match these to a file to update any card numbers to the account number, so

22条回答
  •  说谎
    说谎 (楼主)
    2020-11-21 23:24

    MS Sql

    UPDATE  c4 SET Price=cp.Price*p.FactorRate FROM TableNamea_A c4
    inner join TableNamea_B p on c4.Calcid=p.calcid 
    inner join TableNamea_A cp on c4.Calcid=cp.calcid 
    WHERE c4..Name='MyName';
    

    Oracle 11g

            MERGE INTO  TableNamea_A u 
            using
            (
                    SELECT c4.TableName_A_ID,(cp.Price*p.FactorRate) as CalcTot 
                    FROM TableNamea_A c4
                    inner join TableNamea_B p on c4.Calcid=p.calcid 
                    inner join TableNamea_A cp on c4.Calcid=cp.calcid 
                    WHERE p.Name='MyName' 
            )  rt
            on (u.TableNamea_A_ID=rt.TableNamea_B_ID)
            WHEN MATCHED THEN
            Update set Price=CalcTot  ;
    

提交回复
热议问题