Solved

Oracle 11g Pivot aggrgate sum column

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

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

708 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

15 Experts available now in Live!

Get 1:1 Help Now