MySQL - UPDATE query with SET statement dependent on the outcome of the previous SET statement

后端 未结 2 577
余生分开走
余生分开走 2021-01-23 09:10

Here is a tabular representation of what I would like to achieve with an UPDATE statement.

+----+----+---+---+----+----------+---------------+---------------+
|          


        
2条回答
  •  有刺的猬
    2021-01-23 09:28

    I actually found a solution to this problem using local variables in the SET statements. See below.

    UPDATE [EXAMPLE]
    SET [Calc A]    = @calc_a : = A - B
        , [Calc B]  = @calc_b := @calc_a / D
        , [Calc C]  = B / @calc_b
    

提交回复
热议问题