SQL Update to the SUM of its joined values

后端 未结 7 1428
北恋
北恋 2020-12-04 17:42

I\'m trying to update a field in the database to the sum of its joined values:

UPDATE P
SET extrasPrice = SUM(E.price)
FROM dbo.BookingPitchExtras AS E
INNER         


        
相关标签:
7条回答
  • 2020-12-04 18:22

    An alternate to the above solutions is using Aliases for Tables:

    UPDATE T1 SET T1.extrasPrice = (SELECT SUM(T2.Price) FROM BookingPitchExtras T2 WHERE T2.pitchID = T1.ID)
    FROM BookingPitches T1;
    
    0 讨论(0)
提交回复
热议问题