dbTalk Databases Forums  

Columns in query

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Columns in query in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mtek
 
Posts: n/a

Default Columns in query - 09-15-2008 , 08:00 AM







Hi,

I saw a similar post by someone else but there was no replies.

I need to write a query that will return columns in the same result
row. The trick is that these columns must be decoded, and I think
that the decode statement must have a fallback if no items match.
This will not work if I want to decode each column with a single value
and display it in the same row.....

Like this:

SQL> select * from test;

C1 C2
---------- ----------
REC1 50
REC2 50
REC1 100
REC2 10

A SUM(C2) B SUM(C2)
-------- ---------- -------- ----------
Record 1 150 150
60 Record 2 60

SELECT DECODE(c1, 'REC1','Record 1') a, SUM(C2),
DECODE(c1,'REC2','Record 2') b, SUM(C2)
FROM test
GROUP BY c1;

A SUM(C2) B SUM(C2)
-------- ---------- -------- ----------
Record 1 150 150
60 Record 2 60


What I am looking for is a display like this:

Record 1 150 Record 2 60

Is this even possible?

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.