Solved

Oralce query question

Posted on 2011-02-19
3
344 Views
Last Modified: 2012-05-11
I have an Oracle 11g table and its contents are like this:
ID   V1   F1   F2    F3
=======================
1    p    12   null  null    
2    q    null 11    null
2    r    null null  17
4    r    null null  23
5    p    8    null  null
4    p    18   null  null
4    q    null 56    null
7    p    17   null  null

How can I write a query that will give following O/P:
ID   F1   F2    F3
=======================
1    12   null  null    
2    null 11    17
4    18   56    23
5    8    null  null
7    17   null  null

The Value of V1 in the first table could only be "p", "q" or "r".
If V1=p then we only need its F1 value.
If V1=q then we only need its F2 value.
If V1=r then we only need its F3 value.
And the O/P needs to have unique ID value.
0
Comment
Question by:toooki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 26

Accepted Solution

by:
tigin44 earned 225 total points
ID: 34934767
this may help you

SELECT ID, MIN(F1) AS F1, MIN(F2) AS F2, MIN(F3) AS F3
FROM yourTable
GROUP BY ID
0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 225 total points
ID: 34934844
Just in case the real world requirement requires a little more logic behind it, you can do something similar with case/decode statements:

select id,max(F1) F1,max(F2) F2,max(F3) F2
from
(
select id,
      case when V1='p' then F1 else null end F1,
      case when V1='q' then F2 else null end F2,
      case when V1='r' then F3 else null end F3
from tab1
)
group by id
/
0
 

Author Comment

by:toooki
ID: 34935037
Yes the solution works perfectly.  But my mistake. I assumed that I could create a view like the below table on which I could use the query that you gave to me.
ID   V1   F1   F2    F3
=================

But I could not create such view. Could you please look at the question that I could correctly put here.
http://www.experts-exchange.com/Database/Oracle/Q_26833931.html
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to recover a database from a user managed backup

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question