How to reduce the value from multiple rows by calculation : <p>I have table called : stock  , From that qty will be reduced by priority column in the respective warehouse.</p>

<pre>
-------------------------------------------
Id         SKU    priority  Warehouse  Qty
--------------------------------------------
1          sku1      p1        W1        1
2          sku1      p2        w2        2
3          sku1      p3        w3        3
</pre>

<p>From the above table, 4 qty item will be reduced based on priority.</p>

<p>Expected output :</p>

<pre>
------------------------------------------
Id         SKU    priority  Warehouse  Qty
--------------------------------------------
1          sku1      p1        W1        0
2          sku1      p2        w2        0
3          sku1      p3        w3        2
</pre>

<p>Can anyone suggest how to achieve it.</p>
