Solved

crosstab with oracle

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

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.

Question has a verified solution.

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

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

778 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