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!

Add values of multiple columns to another column

Ranganathan VenkatesanJan 5 2016 — edited Jan 5 2016

Hi,

I have a table with below structure

Transaction DateCountryDivisionEntityFlagTotal
05-Jan-2015GB11CRNew Errors5
05-Jan-2015GB11SpendNew Errors5

I need to display it in below format

Transaction DateCountryDivisionCR-New ErrorsSpend-New ErrorsTotal-New Errors
05-Jan-2015GB115510

If you the see the above format, I want the rows to be transposed to columns based on the FLAG value. One flag entry like "New Errors" will have a multiple Entity (Cr, Spend)

Based on that , we need to group for Transaction Date, Country, Division and show the data.

Sum of the Total Errors in a Particular Flag needs to be displayed in a column.

I have tried below query to transpose the columns.

select t.transaction_dt , t.cntry_id, t.div_id,

nvl(max(decode(t.entity||'-'||t.flag,'CR-New Errors',t.TOTAL)),0) "CR-New Errors",

nvl(max(decode(t.entity||'-'||t.flag,'Spend-New Errors',t.TOTAL)),0) "Spend-New Errors"

from table t

group by t.transaction_dt , t.cntry_id, t.div_id;


In the above query how to get the sum of the total columns for this flag type.

Please help.

This post has been answered by Chris Hunt on Jan 5 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 2 2016
Added on Jan 5 2016
5 comments
4,203 views