Solved

Oracle 11g Pivot aggrgate sum column

Posted on 2014-02-27
3
2,117 Views
Last Modified: 2014-02-27
Using this example below of a simple pivot query, I'm trying to also add a 4th column that sums the previous 3 columns.  So the result looks like this,

CLUSTER  INDEX TABLE SUM
10             468     374      852

select * from (
   select object_type
   from dba_objects
)
pivot
(
   count(object_type)
   for object_type in ('CLUSTER', 'INDEX', 'TABLE')
);
0
Comment
Question by:talahi
  • 2
3 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 39892732
select x.* , clus + ind + tab as sum
 from
(select * from (
   select object_type
   from dba_objects
)
pivot
(
   count(object_type)
   for object_type in ('CLUSTER' as clus, 'INDEX' as ind, 'TABLE' as tab)
)) x;


just need to alias the pivot results
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 39892748
or, you can use the default aliases, but then you'll need to put them in double quotes


SELECT x.*, "'CLUSTER'" + "'INDEX'" + "'TABLE'" AS SUM
  FROM (SELECT *
          FROM (SELECT object_type FROM dba_objects) PIVOT (COUNT(object_type)
                                                     FOR object_type
                                                     IN ('CLUSTER', 'INDEX', 'TABLE'))) x;
0
 

Author Closing Comment

by:talahi
ID: 39892761
Thanks again.  I really appreciate your help.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question