-
Set Membership SQL
Given a table T, with 2 columns Item and RequiredParts.
Where Item is the name of an item and RequiredParts is the name of
a part that an Item depends on.
Example table T:
Item , RequiredParts
A , 1
A , 2
B , 1
B , 3
C , 1
C , 2
C , 3
D , 1
D , 2
So
A depends on 1 & 2
B depends on 1 & 3
C depends on 1, 2 & 3
D depends on 1 & 2
Can a query be written such that the input is
the available Required parts, and the result
is the list of items that have dependencies
fullfilled.
Ex. f(1) = null
f(1,2) = A,D
f(1,2,3) = C
f(1,3) = B
-
Set Membership SQL - Answer
Answer:
SELECT DISTINCT Item FROM T WHERE ITEM NOT IN(SELECT ITEM FROM T WHERE RequiredParts NOT IN(1,2,3))
------------
Mark Marlow at 8/19/99 9:07:44 AM
Given a table T, with 2 columns Item and RequiredParts.
Where Item is the name of an item and RequiredParts is the name of
a part that an Item depends on.
Example table T:
Item , RequiredParts
A , 1
A , 2
B , 1
B , 3
C , 1
C , 2
C , 3
D , 1
D , 2
So
A depends on 1 & 2
B depends on 1 & 3
C depends on 1, 2 & 3
D depends on 1 & 2
Can a query be written such that the input is
the available Required parts, and the result
is the list of items that have dependencies
fullfilled.
Ex. f(1) = null
f(1,2) = A,D
f(1,2,3) = C
f(1,3) = B
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|