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
Solved

get oracle rows as columns

Posted on 2009-07-15
7
707 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
Select and Insert Query running slow 4 45
Sybase and replication server 13 39
SQL2016 to ORACLE11G linked-server 6 28
sum of columns in a row in oracle 3 32
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
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.
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…

809 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