Skip to content
Advertisement

How to update a column based on values of other columns

I have a tables as below

I have to update var_start_date column with min(reporting_date) for each combination of id,code,sub_code and item_nbr only till variance field is zero. Row with variance = 0 should have null var_start_date. and next row after that should have next min(var_start_date.). FYI, variance is calculated as par_cnt-orc_cnt

so my output should look like this –

I am trying to write a function using below query to divide the data into sets.

.But dont know how to include variance field to split the sets.

Advertisement

Answer

Try as below

SQL FIDDLE DEMO

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement