Solved

Multiple joins on different conditions

Posted on 2009-03-31
5
417 Views
Last Modified: 2012-05-06
I need to join different tables on different conditions and group by
select id,
       pdate,
       ptype,
       count(*),
       sum(amount),
 
 from payment PA
   computer  ba,
   network  ca,
   other da
where PA.pdate  BETWEEN TRUNC(sysdate) AND TRUNC(sysdate) + .99999
 
  need to join with computer table if ptype =computer 
  and pa.id=ba.id(+)
 
  need to join with netork  table if ptype =network
  and pa.id=ca.id(+)
 
  need to join with other table if ptype =other
  and pa.id=da.id(+)
 
group by id,pdate,ptype

Open in new window

0
Comment
Question by:mikky7
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:techmaza
ID: 24029372

u need to use procedures or function where u can pass ptype as parameter and use IF ELSE block to get the required select result.

Open in new window

0
 
LVL 41

Expert Comment

by:ralmada
ID: 24029402
try this:
select PA.id,
       PA.pdate,
       PA.ptype,
       count(*),
       sum(PA.amount),
from payment PA
LEFT join computer ba on pa.id=ba.id and ptype = 'computer' 
LEFT join network  ca on pa.id=ca.id and ptype ='network'
LEFT join other da on pa.id=da.id and ptype ='other'
where PA.pdate  BETWEEN TRUNC(sysdate) AND TRUNC(sysdate) + .99999
group by PA.id,PA.pdate,PA.ptype

Open in new window

0
 

Author Comment

by:mikky7
ID: 24029413
Thanks,
So it means not possible to do in one query because this would be part of existing report in perl  
I am looking just one query.
Thanks very much again
0
 
LVL 3

Accepted Solution

by:
techmaza earned 125 total points
ID: 24066623
 if u think my answer is correct and u want to close this topic then u shuld either accept the solution or comment for the solution and wait for another solution.



0
 

Author Comment

by:mikky7
ID: 24092068
Thanks so much and it was really good experience which is fast and accurate

I do no know why we should grade this because eveyone is learning here
Thanks again techmaza:
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now