简体   繁体   中英

Requesting help in translating a SQL query to relational algebra

As part of a assignment at my computer science education, I've been asked to translate a query from SQL to a relational algebra expression.

The idea here behind the query is to find all the rooms, from one single table, which has the equipment types projecter, but not a whiteboard - The following query does that, but now I'm having trouble translating it into a relation algebra expression.

SELECT 
    e.room, e.type
FROM 
    Equipment AS e
LEFT OUTER JOIN 
    Equipment AS e2 ON e.room = e2.room AND e2.type = 'whiteboard'
WHERE 
    e.type = 'projector'
    AND e2.type IS NULL;

I'd appreciate any help in translating this, as I'm quite the newbie and generally do not seem to see the logic here.

the logic is the following. select room, type from equipment where room has a projector. intersect with room from equipment that has a whiteboard. Keep only the part of the intersection that has a projector, but does not have a whiteboard (AND e2.type IS NULL means the room was not found in the whiteboard group)

http://sketchtoy.com/50426780

rewording:

find group A from group ROOM?EQUIPMENT that has projectors
find group B from group ROOM?EQUIPMENT that has whiteboards
Intersect A and B
keep the part of group A where room IDs are not found in group B

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM