update one row in per group
<p>Here I have a table :</p>

<pre><code>+------+------+-------+------+----------+
| id   | year | val   | row  | whatever |
+------+------+-------+------+----------+
| 001  | 2006 |  8    |    1 | p01      |
| 001  | 2003 |  -10  |    2 | p01      |
| 001  | 2008 |  5    |    3 | p01      |
| 001  | 2001 |  -2   |    4 | p01      |
| 002  | 2007 |  5    |    1 | p01      |
| 002  | 2009 |  4    |    2 | p01      |
| 002  | 2002 |  -5   |    3 | p01      |
| 002  | 2004 |  -4   |    4 | p01      |
| 003  | 2005 |  15   |    1 | p01      |
| 003  | 2000 |  -18  |    2 | p01      |
| 003  | 2001 |  -12  |    3 | p02      |
| 003  | 2004 |  12   |    4 | p02      |
| 003  | 2002 |  12   |    5 | p02      |
| 004  | 2003 |  5    |    1 | p02      |
| 004  | 2000 |  -8   |    2 | p02      |
| 004  | 2006 |  4    |    3 | p02      |
| 004  | 2007 |  3    |    4 | p02      |
+------+------+-------+------+----------+
</code></pre>

<p>I want in per group by id, sum of vals=0, if vals &lt;> 0, so result of sum in per group reduce with first vals. for example in id =1 ==> sum =(8)+(-10)+(5)+(-2)=1 , if val's row1 reduce 1, sum equal 0 and ok.</p>

<pre><code>update mytable

set val=val-(
select sum(val) from my table
group by id
)

where row=1
</code></pre>

<p>What is the correct solution in this example?</p>