Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

get oracle rows as columns

Posted on 2009-07-15
7
Medium Priority
?
712 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 375 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Independent Software Vendors: 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

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.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…
Via a live example, show how to take different types of Oracle backups using RMAN.

618 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