Solved

get oracle rows as columns

Posted on 2009-07-15
7
710 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
[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
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 41

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

718 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