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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -