[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Multiple joins on different conditions

Posted on 2009-03-31
5
Medium Priority
?
422 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
[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
  • 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 375 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

650 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