home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sqlware!kevin.bongiovanni
- From: kevin.bongiovanni@sqlware.uunet.UU.NET (Kevin Bongiovanni)
- Newsgroups: comp.databases.oracle
- Subject: RE: ORACLE SQLPLUS MATRIX
- Message-ID: <563.204.uupcb@sqlware.uunet.UU.NET>
- Date: 29 Dec 92 00:56:00 GMT
- Distribution: world
- Organization: SQLWare Inc., Leesburg, VA - (703) 771-3979
- Reply-To: kevin.bongiovanni@sqlware.uunet.UU.NET (Kevin Bongiovanni)
- Lines: 39
-
- In response to your SQLPLUS matrix question...
- I found the following program floating around a book in my office.
- The idea is that you have a table R(A,B,C) such that element A can be
- the row, element B can be the column, and element C the value.
- B1.....Bn
- A1 C1,1...C1,n
- ...
- An Cn,1...Cn,n
- The SQL Script is as follows:
- column x noprint
- set pause off
- set heading off
- set feedback off
- .
- spool temp.sql
- select 0 x,'select <element A>, ' from dual
- union
- select 1 x,'sum(decode(<element B>,''' || <element B> || ''',<element
- C>, 0))' ||' '||<element B>||','
- from <table name>
- where <element B> is not null
- union
- select 2 x,'sum(<element c>) Total from <table name> group
- <element A>;'
- from dual
- order by 1
- /
- spool off
- set header on
- spool result
- start temp
- spool off
- /
-
- ----
- +--------------------------------------------------------------------------+
- | SQLWare BBS 703-771-4158 (HST V.32BIS-Specializing in ORACLE and other |
- | RDBMS topics. Sponsored by SQLWare Inc., Leesburg,VA-300 conferences. |
- +--------------------------------------------------------------------------+
-