Unix Technical Forum

Flipping rows and cols

This is a discussion on Flipping rows and cols within the Oracle Miscellaneous forums, part of the Oracle Database category; --> I need to flip the cols and rows of a table for display purposes. Say my table has three ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 10:13 AM
shabda.raaj@gmail.com
 
Posts: n/a
Default Flipping rows and cols

I need to flip the cols and rows of a table for display purposes. Say
my table has three rows and 20 cols I may want to display the data
after flipping rows as cols. Can anyone point me to the correct place?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 10:13 AM
shabda.raaj@gmail.com
 
Posts: n/a
Default Re: Flipping rows and cols

You might also like to read this.
shabda.r...@gmail.com wrote:
> I need to flip the cols and rows of a table for display purposes. Say
> my table has three rows and 20 cols I may want to display the data
> after flipping rows as cols. Can anyone point me to the correct place?


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 10:13 AM
shabda.raaj@gmail.com
 
Posts: n/a
Default Re: Flipping rows and cols

You might also like to read this.
http://www.codeproject.com/aspnet/Datatable.asp
It does the same thing in ASP.
shabda.r...@gmail.com wrote:
> I need to flip the cols and rows of a table for display purposes. Say
> my table has three rows and 20 cols I may want to display the data
> after flipping rows as cols. Can anyone point me to the correct place?


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 10:13 AM
Mark D Powell
 
Posts: n/a
Default Re: Flipping rows and cols


shabda.raaj@gmail.com wrote:
> You might also like to read this.
> http://www.codeproject.com/aspnet/Datatable.asp
> It does the same thing in ASP.
> shabda.r...@gmail.com wrote:
> > I need to flip the cols and rows of a table for display purposes. Say
> > my table has three rows and 20 cols I may want to display the data
> > after flipping rows as cols. Can anyone point me to the correct place?


You can do this in plain old SQL.

SQL> select
2 process_date
3 ,sum(ws.reqstd_amt * pt.a) as "A Dollars"
4 ,sum(ws.reqstd_amt * pt.e) as "E Dollars"
5 ,sum(ws.reqstd_amt * pt.i) as "I Dollars"
6 ,sum(ws.reqstd_amt * pt.k) as "K Dollars"
7 ,sum(ws.reqstd_amt * pt.v) as "V Dollars"
8 from
9 not_real_name ws
10 ,aeikv_pivot pt
11 where ws.userid_alias = 'DISP TOTAL'
12 and ws.disp_code = pt.value
13 group by process_date
14 /

PROCESS_D A Dollars E Dollars I Dollars K Dollars V Dollars
--------- ---------- ---------- ---------- ---------- ----------
25-JUN-03 1950333.76 357911.44 4375403.45 982284.49 41717.87
26-JUN-03 1724270.12 264826.83 5074678.6 877965.21 41717.87
<snip>

The pivot table conists of X rows with X columns defined. All column
values are 0 except for the Nth column on the Nth which are 1 so that
the 1's form a diagnal from the upper left to the lower right where all
rows are selected.

SQL> select * from aeikv_pivot
2 /

V A E I K V
- - - - - -
A 1 0 0 0 0
E 0 1 0 0 0
I 0 0 1 0 0
K 0 0 0 1 0
V 0 0 0 0 1


Here is a link to a thread with references on the topic which leads to
information on other approaches:
http://groups.google.com/group/comp....e2c08b 611b14

Analytic queries can be used to do this as well as the connect by
clause.

HTH -- Mark D Powell --

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:04 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com