Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

aggregating non-numeric data into columns

user8810711Sep 8 2009 — edited Sep 9 2009
Hi,

I'm pretty new to SQL and am hoping someone here can help me. I have a table of survey results where each record = one student's open-ended response to one question. Not every student answered every question, so the table looks like this:

userid | questionid | textresponse
101 | 35 | Here's a comment about question 35.
101 | 36 | Here's a comment about question 36.
101 | 37 | Here's a comment about question 37.
102 | 35 | I only wrote a comment about 35.
103 | 36 | I only wrote a comment about 36.
104 | 36 | Here's my answer for 36.
104 | 37 | Here's my answer for 37.

I want to write a query that creates a results set where each record = one userid, and each question is a column, like this:
userid | 35 | 36 | 37
101 | Here's a comment about question 35. | Here's a comment about question 36. | Here's a comment about question 37.
102 | I only wrote a comment about 35. | (null) | (null)
103 | (null) | I only wrote a comment about 36. | (null)
104 | (null) | Here's my answer for 36. | Here's my answer for 37.

Can someone give me instructions (geared for a beginner) on how to do this using Oracle 10g? Someone suggested the CUBE function, but that seems to be for aggregating non-numeric data. Any help would be greatly appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 7 2009
Added on Sep 8 2009
6 comments
1,588 views