Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion SQL Query: Switching Rows to Columns dynamically.
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Anil G  
View profile  
 More options Oct 16 2006, 6:45 pm
Newsgroups: comp.databases.oracle.misc
From: "Anil G" <anil.got...@gmail.com>
Date: 16 Oct 2006 15:45:11 -0700
Local: Mon, Oct 16 2006 6:45 pm
Subject: SQL Query: Switching Rows to Columns dynamically.
Guys:

I am looking to develop SQL query which will switch the rows to
Columns. I was trying with DECODE statements but that leads to
hardcoding of types. Any one has any clues to develop dynamic logic to
convert rows to columns. Following is detailed information about
problem.

Thanks in advance,
Anil G

----------------------------------------- problem statement
---------------------------------------------------------------
type_tbl
+ name

data_tbl
+ org
+ type_name
+ data_value (FK to type_tbl)

-----
Data layouts: type_tbl, user can keep adding types from the
application.

type_tbl
--------
T-1
T-2
T-3
T-4
..
..

data_tbl
-------
org                     type_name       data_value
----            ---------               -----------
O-1                     T-1                                             100
O-1                     T-2                                             30
O-1                     T-3                                             45
O-2                     T-1                                             100
O-2                     T-4                                             30
O-3                     T-1                                             45

Desired Output:
---------------------------------------------------

org     T-1     T-2     T-3     T-4 .....
--- --- ---     ---     ---     --
O-1     100     30      45
O-2     100     0               0               25
O-3     45

--------------------------------------------------------- Ends
-------------------------------------------------------------


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.