Home » SQL & PL/SQL » SQL & PL/SQL » Need a Help to get best output (merged)
Need a Help to get best output (merged) [message #343820] Thu, 28 August 2008 05:06 Go to next message
akalinga
Messages: 2
Registered: August 2008
Location: Malaysia
Junior Member


I have a table like this

DeptName EmpNo
A 1
A 2
B 3
B 4

I required output like this



A B
1 Null
2 Null
Null 3
Null 4

what's the best way to write a pl/sql select query

Re: PL/SQL Output [message #343833 is a reply to message #343820] Thu, 28 August 2008 05:46 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
read the posting guidelines, follow them, edit your post to adhere to those guidelines.
Need a Help to get best output [message #344142 is a reply to message #343820] Thu, 28 August 2008 20:33 Go to previous messageGo to next message
akalinga
Messages: 2
Registered: August 2008
Location: Malaysia
Junior Member
Below method i tried with decode statement but deptname is vary and will not be consistant. So decode will be bitt tuff in that situation.

Kinldy give me a good method to get the output as below.

I have a table like this

DeptName EmpNo
A 1
A 2
B 3
B 4

I required output like this



A B
1 Null
2 Null
Null 3
Null 4

Thanks for everyone
Re: Need a Help to get best output [message #344143 is a reply to message #344142] Thu, 28 August 2008 20:46 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://www.orafaq.com/forum/t/88153/0/
Please read & FOLLOW the Posting Guidelines as stated in URL above
Re: Need a Help to get best output [message #344161 is a reply to message #344142] Fri, 29 August 2008 00:10 Go to previous messageGo to next message
flyboy
Messages: 1903
Registered: November 2006
Senior Member
Although this is not a classical pivot query, you may use its technique to get the desired result.
The description can be found e.g. on http://www.orafaq.com/wiki/PIVOT.
Re: Need a Help to get best output [message #344162 is a reply to message #344142] Fri, 29 August 2008 00:11 Go to previous messageGo to next message
Michel Cadot
Messages: 68737
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
It is useless to create an new topic with the same question, above all with the same error: not reading the guidelines.
The result: you have the same answer.

Just follow the rules and you will have an answer.

Regards
Michel
Re: Need a Help to get best output [message #344177 is a reply to message #344162] Fri, 29 August 2008 00:36 Go to previous messageGo to next message
hamidmahmood
Messages: 30
Registered: August 2006
Member
Check this


SELECT CASE WHEN name='A'
THEN dept_no
ELSE
null
END AS A,
CASE WHEN name='B'
THEN dept_no
ELSE
null
END AS B
FROM test_12
Re: Need a Help to get best output [message #344178 is a reply to message #344177] Fri, 29 August 2008 00:38 Go to previous messageGo to next message
Michel Cadot
Messages: 68737
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
As for the previous answer you gave:
Michel Cadot wrote on Thu, 28 August 2008 09:18
@hamidmahmood,

Follow the guidelines:
- format your post
- don't give solution just clue

OraFAQ Forum Guide, "How to format your post?" section.
OraFAQ Forum Guide, "Responding to Posts" section:
Quote:
When responding to questions, if it is obviously a student with a homework assignment or someone else just learning, especially in the homework and newbies forums, it is usual to provide hints or clues, perhaps links to relevant portions of the documentation, or a similar example, to point them in the right direction so that they will research and experiment on their own and learn, and not provide complete solutions to problems. In cases where someone has a real-life complex work problem, or at least it may seem complex to them, it may be best to provide a complete demo and explanation.



Regards
Michel
Re: Need a Help to get best output [message #344180 is a reply to message #344178] Fri, 29 August 2008 00:42 Go to previous messageGo to next message
hamidmahmood
Messages: 30
Registered: August 2006
Member
Thanks
for this Next time

i do this only provied hints
Re: Need a Help to get best output (merged) [message #344182 is a reply to message #343820] Fri, 29 August 2008 00:48 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
hamidmahmood,
do not go away mad; just go away & do not return

We do not need hints.
Previous Topic: What Is pivot table? Any example?
Next Topic: Number datatype Format
Goto Forum:
  


Current Time: Fri Feb 14 14:55:44 CST 2025