sql - Compare rows and calculate column of same row -
if see 2 abc's calculate total 9*2 = 18 , second row 15*2 = 30
add fun1 fun2 fun3 9 abc wxy abc 15 def abc abc
a series of case
expressions should trick:
select add * ((case fun1 when 'abc' 1 else 0 end) + (case fun2 when 'abc' 1 else 0 end) + (case fun3 when 'abc' 1 else 0 end)) total mytable
Comments
Post a Comment