Home » SQL & PL/SQL » SQL & PL/SQL » Transpose Columns to Row group by (Oracle)
Transpose Columns to Row group by [message #651529] Thu, 19 May 2016 10:39 Go to next message
dimveg
Messages: 1
Registered: May 2016
Junior Member
Hi to all,

I have a question how to write a query as i am not that experienced with sql

My table is somthing like that

ID_A|Start_Date|End_Date
-------------------------
A | t1 | t2
A | t3 | t4
B | t5 | t6
B | t7 | t8
B | t9 | t10
C | t11 | t12

Is there a way to take the below resuslt? i tried to use a combination of row number & partition over but my poor know how didn't give the result i need

ID_A|Start_Date_1|End_Date_1|Start_Date_2|End_Date_2|Start_Date_3|End_Date_3|
------------------------------------------------------------------------------
A | t1 | t2 |t3 |t4
B | t5 | t6 |t7 |t8 |t9 |t10
C | t11 | t12

thanks in advance
Re: Transpose Columns to Row group by [message #651530 is a reply to message #651529] Thu, 19 May 2016 10:44 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Welcome to this forum.

Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.


Re: Transpose Columns to Row group by [message #651533 is a reply to message #651529] Thu, 19 May 2016 13:20 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Welcome to the forum.
Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Also always post your Oracle version, with 4 decimals, as solution depends on it.

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

This is a standard PIVOT query, please search for this term.

Re: Transpose Columns to Row group by [message #651557 is a reply to message #651529] Fri, 20 May 2016 01:30 Go to previous message
Barbara Boehmer
Messages: 9088
Registered: November 2002
Location: California, USA
Senior Member
http://orafaq.com/wiki/PIVOT
Previous Topic: Query reporting
Next Topic: sysdate in the pivot in clause
Goto Forum:
  


Current Time: Fri Apr 19 09:59:21 CDT 2024