我有两张表就是这样......
table2015 table2016
=======+===========+======== =======+===========+========
id |remains |days_off id |remains |days_off
=======+===========+======== =======+===========+========
1 |4 |12 1 |12 |12
2 |-2 |12 2 |12 |12
3 |3 |25 3 |25 |25
如果table2015上的遗留物小于0,我怎么能在table2016上编辑days_off?这是需要的结果:
table2015 table2016
id |remains |days_off id |remains |days_off
=======+===========+======== =======+===========+========
1 |4 |12 1 |12 |12
2 |-2 |12 2 |12 |10
3 |0 |25 3 |25 |25
我已经尝试过此查询,但它在第5行给了我一个错误
UPDATE
table2016
SET
table2016.days_off = table2016.days_off + table2015.remains
FROM
table2016
JOIN
table2015
ON
table2016.id = table2015.id
AND
table2015.remains < 0