Solved

Oracle 11g Pivot aggrgate sum column

Posted on 2014-02-27
3
1,988 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 73

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 73

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now