Solved

crosstab with oracle

Posted on 1997-12-17
1
2,552 Views
Last Modified: 2008-02-01
How can i get a crosstab with oracle sql ?
0
Comment
Question by:pifede
[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
1 Comment
 
LVL 2

Accepted Solution

by:
scjonson earned 50 total points
ID: 1081286
In order to get a crosstab in SQL you need to use the Decode statement.  The values accross the top need to be known.  The values down the left will be the column which is grouped by.

If an individual table has a column for age and a column for gender here's what you'd do:

SELECT Age,
              sum(decode(v_gender,'F',1,0)) "Female",
              sum(decode(v_gender,'M','1',0)) "Male"
FROM individual
group by age

The results would look like:
      Age    Female      Male
     ---------    ---------     ---------
       17         1              2
       18         0              4
       19         3            11
       20        11           19
       21        14           21
       22        12             9
       23         5            20
    etc.

To make a dynamic crosstab report dynamic SQL would have to be used.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
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…

730 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