Solved

crosstab with oracle

Posted on 1997-12-17
1
2,523 Views
Last Modified: 2008-02-01
How can i get a crosstab with oracle sql ?
0
Comment
Question by:pifede
1 Comment
 
LVL 2

Accepted Solution

by:
scjonson earned 50 total points
Comment Utility
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

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.

Join & Write a Comment

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now