sql server - How to update column of a table after group by with condition in SQL? -
i new user of sql
c#
. i'm faced problem, have sql table column
these are:
id, receiptno, modelname, size, quantity, priceperunit, totalprice.
after group size
column want update
'quantity
' column condition.
condition is, want decrease/minus/less/update 'quantity
' row after row. when 'quantity' '0' jump next row & find quantity & decrease this.
here data:
|id | |receiptno| |modelname| |size| |quantity| |priceperunit| |totalprice| --------------------------------------------------------------------------- |1| |001| |abcd| |xxl| |0| |120| |0| |2| |002| |abcd| |xxl| |6| |120| |720| |3| |003| |abcd| |xxl| |7| |120| |840| |4| |004| |appp| |xl | |2| |60 | |120|
i want decrease first 3 rows '8
' quantities using group size column. how that?
you should able :
update your_table set quantity = quantity - 1 quantity <>0 , size = 'xxl' , id = (select top 1 id your_table quantity = (select min(quantity) your_table size='xxl') )
it decrease quantity first line of size 'xxl' quantity minimum.
this decrease one. might able call 8 time :)
i haven't test request. may need adjustment.
Comments
Post a Comment