SQL Query for division equivalent in relational algebra

172 views Asked by At

The following are my tables,

Staff(enum,etitle,ename), pk:enum

Has(enum,anum), pk:(enum,anum), fk1:Has(enum)->Staff(enum), fk2:Has(anum)->Area(anum)

Area(anum,aname), pk:anum

Problem:

The staff (enum, ename, etitle) who specialize in every medical area.

I have tried the following,

I know that the relational algebra expression for this query would be

divide (Staff join Has) by (project area over anum)

My SQL query is the following:

select S.enum
from Staff S
where not exists
(select A.anum from Area A)
minus
(select H.anum 
from Has H,Staff S1
where H.enum = S1.enum)

But no rows are being returned. I made sure that there is one staff member who specializes in every area.

What I think should be done:

The each staff member's areas must be subtracted from all the areas. If there exists a staff member with all medical areas, then the subtraction would return a null set and the not exists would be satisfied. Then we have to retrive the enum,ename,etitle for the particular staff member.

Note:

This is my homework. I'm posting this after trying very hard.

1

There are 1 answers

0
Multisync On
select * from Staff 
where enum in (
    select enum from (
        select enum, count(distinct anum) as number_of areas
        from Has group by enum
    ) where number_of areas = (select count(*) from Area)
);
  1. For each enum calculate the number of unique areas.
  2. Check that this number equals to the whole number of areas