My table:
ID NAME COST PAR P_val S_val
1 X 5 0 1 0
1 y 5 0 2 0
1 z 5 0 0 5
2 XY 4 0 4 4
I need to update the PAR
field with the SUM(S_val)
, grouped by ID:
- For ID 1
PAR
should be SUM(SVAL) WHERE ID=1
- For ID 2
PAR
should be SUM(SVAL) WHERE ID=2
Expected ouput:
ID NAME COST PAR P_val S_val
1 X 5 5 1 0
1 y 5 5 2 0
1 z 5 5 0 5
2 XY 4 4 4 4
How can I UPDATE
the PAR
value?
My code:
UPDATE Table_Name SET PAR = (SELECT SUM(S_val) FROM Table_Name WHERE ID=1)
FROM Table_Name
This does not work.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…