Solved

get oracle rows as columns

Posted on 2009-07-15
7
699 Views
Last Modified: 2012-05-07
I need to write a report from oracle sql that outputs the rows like columns so the analyst can compare the value
The output from oracle comes out to be
Year month   Product   Stats
200901         ABC          50.00
200902         ABC           40.00

it should look like
Product  Jan2009   STATS    Feb 2009  STATS  DElta (col3-5)
0
Comment
Question by:mahjag
  • 4
  • 2
7 Comments
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24865540
Are you looking for an arbitrary number of columns or just the two columns with the delta?
0
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 125 total points
ID: 24865555
Assuming table name is samp

select yearmonth1, stats1, yearmonth2, stats2, stats1 - stats2 as delta from

 (select yearmonth as yearmonth1, stats as stats1 from samp where yearmonth = to_date('200901', 'yyyymm')) a,

 (select yearmonth as yearmonth2, stats as stats2 from samp where yearmonth = to_date('200902', 'yyyymm')) b

;

Open in new window

0
 

Author Comment

by:mahjag
ID: 24866164
I changed table name and executed it and I got dup rows of about 300 - am I missing any join here
0
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.

 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24866312
The sample data you gave contained only two rows. Perhaps you can explain your data in more detail?
0
 
LVL 40

Expert Comment

by:Sharath
ID: 24866844
How many rows and columns you have in your table?
0
 

Author Comment

by:mahjag
ID: 24869540
I got the sql t work it was missing the where clause which I have to restrict,my only question is the table that I am refering to is already a view of 2 bigger tables of more than million rows, the query takes more time to execute just for a month as against directly querying the table for a month -
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24869719
Yes, that is because views do not help speed up anything. they are simply stored queries. If you want to speed it up you'll need to create indexes on the columns that you are searching / limiting by.

Possibly the month column is not indexed.
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

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
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…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
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.

744 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

10 Experts available now in Live!

Get 1:1 Help Now