dbTalk Databases Forums  

SubQuery Question

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss SubQuery Question in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Paul Izzo
 
Posts: n/a

Default SubQuery Question - 02-18-2005 , 03:13 AM






I have 2 tables that contain Schedule information. The first table
contains Work Order's and the second table contains Task information.

A given Work Order is composed of any combination of Tasks. Example:

Work Order = Car
Task 1 = Wheel Install
Task 2 = Wheel Install
Task 3 = Wheel Install
Task 4 = Wheel Install

What I'm looking for is a way to find all Work Orders that contain only
4 tasks. There's no feild in the tables that specify how many Tasks are
part of a Work Order.

I have the feeling in my gut that I need to do this query using a
subquery. My only problem is that I don't know how to filter out Work
Orders with less than 4 Tasks as well as those with more than 4 Tasks.


Reply With Quote
  #2  
Old   
Tom
 
Posts: n/a

Default Re: SubQuery Question - 02-18-2005 , 03:45 AM






Work order = A Car=B
select * from A,B
where /*use correct join*/
rownnum <= 4
order by Task1


"Paul Izzo" <paul.izzo (AT) mosca-ag (DOT) com> wrote

Quote:
I have 2 tables that contain Schedule information. The first table
contains Work Order's and the second table contains Task information.

A given Work Order is composed of any combination of Tasks. Example:

Work Order = Car
Task 1 = Wheel Install
Task 2 = Wheel Install
Task 3 = Wheel Install
Task 4 = Wheel Install

What I'm looking for is a way to find all Work Orders that contain only
4 tasks. There's no feild in the tables that specify how many Tasks are
part of a Work Order.

I have the feeling in my gut that I need to do this query using a
subquery. My only problem is that I don't know how to filter out Work
Orders with less than 4 Tasks as well as those with more than 4 Tasks.




Reply With Quote
  #3  
Old   
Vikas Chahal
 
Posts: n/a

Default Re: SubQuery Question - 02-18-2005 , 07:39 AM



Hi,

the query below should solve ur problem assuming that work & task table
had a relation based on order_id

for count of less than 4

select work_order.order_id,
sum(task.order_id)
from work_order, task
where work_oder.order_id=task.order_id
group by work_order
having count(*) < 4

& for count of greater than 4

select work_order.order_id,
sum(task.order_id)
from work_order, task
where work_oder.order_id=task.order_id
group by work_order
having count(*) >4


Reply With Quote
  #4  
Old   
its not me
 
Posts: n/a

Default Re: SubQuery Question - 02-18-2005 , 06:22 PM



On 18 Feb 2005 01:13:45 -0800, "Paul Izzo" <paul.izzo (AT) mosca-ag (DOT) com>
wrote:

Quote:
I have 2 tables that contain Schedule information. The first table
contains Work Order's and the second table contains Task information.

A given Work Order is composed of any combination of Tasks. Example:

Work Order = Car
Task 1 = Wheel Install
Task 2 = Wheel Install
Task 3 = Wheel Install
Task 4 = Wheel Install

What I'm looking for is a way to find all Work Orders that contain only
4 tasks. There's no feild in the tables that specify how many Tasks are
part of a Work Order.

I have the feeling in my gut that I need to do this query using a
subquery. My only problem is that I don't know how to filter out Work
Orders with less than 4 Tasks as well as those with more than 4 Tasks.
I suggest you look at using the exists command combining it with
count.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com


Reply With Quote
  #5  
Old   
its not me
 
Posts: n/a

Default Re: SubQuery Question - 02-18-2005 , 07:00 PM



On 18 Feb 2005 01:13:45 -0800, "Paul Izzo" <paul.izzo (AT) mosca-ag (DOT) com>
wrote:

Quote:
I have 2 tables that contain Schedule information. The first table
contains Work Order's and the second table contains Task information.

A given Work Order is composed of any combination of Tasks. Example:

Work Order = Car
Task 1 = Wheel Install
Task 2 = Wheel Install
Task 3 = Wheel Install
Task 4 = Wheel Install

What I'm looking for is a way to find all Work Orders that contain only
4 tasks. There's no feild in the tables that specify how many Tasks are
part of a Work Order.

I have the feeling in my gut that I need to do this query using a
subquery. My only problem is that I don't know how to filter out Work
Orders with less than 4 Tasks as well as those with more than 4 Tasks.
eg:
SELECT t.*
,w.*
FROM workorders w
,tasks t
WHERE w.order_id = t.order_id
AND 4 = (SELECT COUNT (t2.task_id)
FROM fundgroups t2
WHERE t2.order_id = w.order_id)

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com


Reply With Quote
  #6  
Old   
Paul Izzo
 
Posts: n/a

Default Re: SubQuery Question - 02-21-2005 , 02:21 AM



These are all great suggestions guys and I feel that I'm getting
closer to solving my problem. I took your suggestions Vikas and made
them into 1 select statement that looks like this:

select papp.WORKPLAN_NR,sum(papp.UNIT_NR)
from w100.papp,w100.papk
where papp.WORKPLAN_NR = papk.WORKPLAN_NR
group by papp.WORKPLAN_NR
having sum(decode(UNIT_NR,3400,1,3500,1,3430,1)) != 3

With this select statement I get all the records I don't want (this
is good) but I get the problem when I try to combine the select
statement with another. I'd like to do something like this:

select papp.WORKPLAN_NR,sum(papp.UNIT_NR)
from w100.papp,w100.papk
where papp.WORKPLAN_NR = papk.WORKPLAN_NR
group by papp.WORKPLAN_NR
having sum(decode(UNIT_NR,3400,1,3500,1,3430,1)) = 3
not in
(select papp.WORKPLAN_NR,sum(papp.UNIT_NR)
from w100.papp,w100.papk
where papp.WORKPLAN_NR = papk.WORKPLAN_NR
group by papp.WORKPLAN_NR
having sum(decode(UNIT_NR,3400,1,3500,1,3430,1)) != 3 )

But this doesn't work. Does anyone know how I can join the 2 select
statements?


Reply With Quote
  #7  
Old   
Paul Izzo
 
Posts: n/a

Default Re: SubQuery Question - 02-21-2005 , 02:38 AM



These are all great suggestions guys and I feel that I'm getting
closer to solving my problem. I took your suggestions Vikas and made
them into 1 select statement that looks like this:

select papp.WORKPLAN_NR,sum(papp.UNIT_NR)
from w100.papp,w100.papk
where papp.WORKPLAN_NR = papk.WORKPLAN_NR
group by papp.WORKPLAN_NR
having sum(decode(UNIT_NR,3400,1,3500,1,3430,1)) != 3

With this select statement I get all the records I don't want (this
is good) but I get the problem when I try to combine the select
statement with another. I'd like to do something like this:

select papp.WORKPLAN_NR,sum(papp.UNIT_NR)
from w100.papp,w100.papk
where papp.WORKPLAN_NR = papk.WORKPLAN_NR
group by papp.WORKPLAN_NR
having sum(decode(UNIT_NR,3400,1,3500,1,3430,1)) = 3
not in
(select papp.WORKPLAN_NR,sum(papp.UNIT_NR)
from w100.papp,w100.papk
where papp.WORKPLAN_NR = papk.WORKPLAN_NR
group by papp.WORKPLAN_NR
having sum(decode(UNIT_NR,3400,1,3500,1,3430,1)) != 3 )

But this doesn't work. Does anyone know how I can join the 2 select
statements?


Reply With Quote
  #8  
Old   
Sybrand Bakker
 
Posts: n/a

Default Re: SubQuery Question - 02-21-2005 , 07:49 AM



On 21 Feb 2005 05:04:09 -0800, "Paul Izzo" <paul.izzo (AT) mosca-ag (DOT) com>
wrote:

Quote:
test reply
Please stop wasting bandwith, and forcing people to read irrelevant
replies, use the test groups instead


--
Sybrand Bakker, Senior Oracle DBA


Reply With Quote
  #9  
Old   
Paul Izzo
 
Posts: n/a

Default Re: SubQuery Question - 02-22-2005 , 06:58 AM



Thanks Sybrand for your concerns I've since removed all "test"
replies. This query that we're attempting is futile because my boss
changed his mind.

I'd like to thank everyone for their help on the subject.

The new query is a bit more strange but I'll open up a seperate
thread on this one.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.