Solved

crosstab with oracle

Posted on 1997-12-17
1
2,558 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
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.
This video shows how to recover a database from a user managed backup

696 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