Home » SQL & PL/SQL » SQL & PL/SQL » Converting returned rows into columns (Oracle 11)
Converting returned rows into columns [message #675848] Tue, 23 April 2019 16:39 Go to next message
ssmith001
Messages: 35
Registered: August 2018
Member
Looking for some SQL expertise to assist with my dilemma. I have a query below the generates the four rows shown below the query. I need a way to get the four rows into a single row, with column headers of LOAD_ID, DRIVER(S), TRACTOR, & TRAILER.

SELECT
LL.LD_LEG_ID LOAD_ID,
DA.DRVR_CD,
DR.DRVR_NAME
FROM LD_LEG_T LL
JOIN DRVR_ASSN_T DA on DA.LD_LEG_ID = LL.LD_LEG_ID
JOIN DRVR_T DR ON DR.DRVR_CD = DA.DRVR_CD
WHERE LL.LD_LEG_ID = 1614

I've attached a PDF of how the data rows look, and how I am trying to get them to show in a single row with slightly different column headers.



  • Attachment: Book1.pdf
    (Size: 28.82KB, Downloaded 88 times)
Re: Converting returned rows into columns [message #675849 is a reply to message #675848] Tue, 23 April 2019 17:59 Go to previous messageGo to next message
BlackSwan
Messages: 26538
Registered: January 2009
Location: SoCal
Senior Member
https://community.oracle.com/thread/4265305

Please read and follow the forum guidelines, to enable us to help you:
OraFAQ Forum Guide
How to use {code} tags and make your code easier to read
Re: Converting returned rows into columns [message #675854 is a reply to message #675849] Wed, 24 April 2019 05:52 Go to previous messageGo to next message
Bill B
Messages: 1868
Registered: December 2004
Senior Member
I woild love to help but I will never download anything from a public forum. Too much danger of being infected
Re: Converting returned rows into columns [message #675907 is a reply to message #675848] Sun, 28 April 2019 06:26 Go to previous message
Satheeshkumar.P
Messages: 4
Registered: June 2018
Location: Namakkal
Junior Member
GROUP BY ROWS INTO COLUMNS

SELECT LD_LEG_ID, LISTAGG (DRVR_NAME, ',') WITHIN GROUP (ORDER BY 2), DRVR_CD
FROM LD_LEG_T
GROUP BY LD_LEG_ID, DRVR_CD
Previous Topic: Inserting %RowType objects "faster"
Next Topic: Design Question
Goto Forum:
  


Current Time: Mon Jun 17 14:02:18 CDT 2019