Solved

Oracle 11g Pivot aggrgate sum column

Posted on 2014-02-27
3
2,251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
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.
Via a live example, show how to take different types of Oracle backups using RMAN.

740 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