Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Group by Field Contents 1

Status
Not open for further replies.

jetechie

Technical User
May 23, 2006
15
US
TABLE_A
-------
QUESTION_NO
ANSWER


TABLE_A
-----
QUESTION_NO ANSWER
1 20
2 30
3 50
4 50
5 20
6 20


Is there a way I can group by the QUESTION_No? Like, if I wanted the results to be like this.
QUESTIONS VALUES
1-3 100
4-6 90

Thanks for any guidance!

 
JE,

Here is code for you:
Code:
col a heading “Questions” format a9
col b heading “Values” format 999
select decode(question_no,1,’1-3’,2,’1-3’,3,’1-3’
                         ,4,’4-5’,5,’4-5’,6,’4-5’)a
      ,sum(answer)b
from table_a
group by decode(question_no,1,’1-3’,2,’1-3’,3,’1-3’
                         ,4,’4-5’,5,’4-5’,6,’4-5’);

Questions Values
--------- ------
1-3          100
4-5           90
Let us know how this works for you.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I can provide you with low-cost, remote Database Administration services: see our website and contact me via www.dasages.com]
 
JE,

In my code, above, any occurrence of the string "4-5" should change to "4-6". Otherwise, the results match your specifications.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I can provide you with low-cost, remote Database Administration services: see our website and contact me via www.dasages.com]
 
Sweet!!! Thanks! That's exactly what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top