Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to sum row value for every column

CostaJul 31 2018 — edited Jul 31 2018

Hi All,

I want to sum the value of all parameters grouping by event and then arrange the score in descending order. How can I do so.

with t as

(select 'Asthma' as event, 1 as f1, 0 as f2 , 0 as f3, 1 as f4 from dual union

select 'Fever',1,1,1,1 from dual union

select 'Fever',1,0,0,1 from dual union

select 'Asthma',1,1,1,1 from dual union

select 'Asthma',1,1,1,1 from dual union

select 'Asthma',0,1,1,1 from dual union

select 'Acidity',1,0,1,0 from dual union

select 'heart attack',1,1,1,1 from dual)

select t.* , sum(f1+f2+f3+f4) as T_score from t

group by event, f1,f2,f3,f4

order by 1

My Output

  

EVENTF1F2F3F4Overall_score
Asthma22239
Fever21126
heart attack11114
Acidity10102
This post has been answered by Frank Kulash on Jul 31 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 28 2018
Added on Jul 31 2018
4 comments
4,679 views