×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

FIELD from row to COLUMN

FIELD from row to COLUMN

FIELD from row to COLUMN

(OP)
Hello

I have my select statement returns something like this:

id episode name
1 1 john
2 1 mary
3 1 null

is it posible get a result like this?

episode
1 john mary null

I have tried with pivot but with I need an aggregate function which I do not use,

can anyone guide me!!

Thanks in advance

RE: FIELD from row to COLUMN

(OP)
HI

I find a posible solution

I find this instruction

select id_episode, listagg(nvl(name,'noname'), '|' ) within group (order by name) as names
from opinion where id_episode = 1
group by id_episode order by id_episode

this returns:

id_episode names
1 john|mary|noname

This workaround serves me for a while, hope this help you too, or if you can make field "names" to three columns I would appreciate you share.



Regards.

RE: FIELD from row to COLUMN

If you have a way to rank the records you want to put into columns, do this is a subquery, then feed this information to an outer query where you do the group by.
General example.

select
id_espisode,
max(case when rnk = 1 then name else null end) as 1stname,
max(case when rnk = 2 then name else null end) as 2stname,
max(case when rnk = 3 then name else null end) as 3rdname
From
(
select
id_espisode,
name,
rank() over(partition by id_espisode order by whatwillrankrecords) as rnk
from opinion
)
group by
id_espisode

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close