Solved

Crosstab Query

Posted on 2003-11-23
2
2,983 Views
Last Modified: 2011-09-20
In MS Access, there is a command TRANSFORM... PIVOT... to produce a crosstab query.

Is there any command or functions that is similar to the TRANSFORM... PIVOT... command of MS Access??

0
Comment
Question by:shlikjohn
2 Comments
 
LVL 15

Expert Comment

by:andrewst
ID: 9809523
Reporting tools have such features - e.g. Oracle Reports can create "matrix reports".   SQL Plus and the SQL language do not.  A standard way to create a crosstab query in Oracle SQL is:

select s.region,
         sum( decode( s.year, 2001, s.value, 0 )) sales_2001,
         sum( decode( s.year, 2002, s.value, 0 )) sales_2002,
         sum( decode( s.year, 2003, s.value, 0 )) sales_2003,
         ...
from sales s
where ...
group by s.region;
 
0
 
LVL 35

Accepted Solution

by:
Mark Geerlings earned 100 total points
ID: 9810484
The simple answer is: No.  The comment from andrewst describes the two most common ways to accomplish this in Oracle, but they each have disadvantages.  The first approach requires buying (and learning to use) Oracle Reports, and this is not the most user-friendly reporting tool on the market.  The second approach (with "decode") requires you to know and write code for all of the different possible values in the data.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
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…
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 how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

786 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