Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have base_value1=100 and base_value2=200 and this table:
id    val    type1     b_v_type
1     10     1          1
2     5      2          2
3     25     1          1
4     40     1          2

I want to have this result with a query:
val    base_value1     base_value2
10          110            null
5           null            195
25          135            null
40          null            235
SQL



What I have tried:

first I execute this query:
select val,null as base_value1, null as base_value2
from t

after that I run this update query:
update t
set @base_value1=base_value1=@base_value1+ case when type1=1 then val
                                                when type1=2 then val*-1
                                           end
when b_v_type=1

update t
set @base_value2=base_value2=@base_value2+ case when type1=1 then val
                                                when type1=2 then val*-1
                                           end
when b_v_type=2

but it does not work properly
Posted
Updated 1-Nov-22 20:25pm
v3

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900