Skip to Main Content

Oracle Database Discussions

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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Swap both Rows and Columns Without aggregate

rgiljohannMar 7 2023 — edited Mar 7 2023

I am looking to find a query to swap my columns and rows where my table does not have a number.

Below are the specifics. My AuditID field is a sequential number, and all my fields start with ‘X’, and the values in those fields are ‘Yes’, ‘No’, or ‘N/A’.

I am looking to put my AUDITID field in columns, and put each ‘X’ field as a new row.

The X fields are used in a form, and the admin users would like to see each question (each ‘X’ field) as a row with each response listed out left to right (AUDITID left to right) so that they can see responses by question easily.

Base Table using this query:

select 
AUDITID
,X1A
,X1B
,X2A
,X2B
,X2C
from AUDIT_FORM_PREBILL_HHA

Result:

Desired Output:

This post has been answered by Frank Kulash on Mar 7 2023
Jump to Answer
Comments
Post Details
Added on Mar 7 2023
4 comments
917 views