开发者

Relational Algebra

Can you please help me solve this in Relational Algebra? I've got this DB (Thesis Defense);

  • Teachers(Teacher_ID, Name, Specialty)
  • Projects(Project_ID, Title, Specialty)
  • Thesis(Thesis_ID, Project_ID, Jury_ID, Decision)
  • Juries(Jury_ID, Supervisor_ID, First_Member_ID, Second_Member_ID)

I want to find the algebr开发者_如何学JAVAaic query to get the teachers (ID, Name) that supervises thesis in their specialty;

I did it in SQL already, this is how it should look like:

Select Teacher_ID, Name  
From Teachers T  
Where Teacher_ID IN
      (Select Supervisor_ID  
       From Juries  
       Where Jury_ID IN
             (Select Jury_ID  
              From Thesis  
              Where Project_ID IN 
                    (Select Project_ID  
                     From Projects P  
                     Where T.Specialty = P.Specialty)))  

Thanks for your help!


Are you trying to do this?

select Te.Teacher_ID,Te.Name from thesis t
join project P on (T.Speciality =P.Speciality)
join Juries J on ( J.jury_ID = T.Jury_id)
join Teacher Te on (Te.Teacher_ID = J.Supervisor_ID)


I think I've found the answer to my question, thanks to Mulki's help:

R1 <- Thesis ⋈ (Project_ID) Projects
R2 <- Teachers ⋈ (Teacher_ID=Supervisor_ID) Juries
R3 <- π Teacher_ID, Name (R2 ⋈ (Specialty ^ Jury_ID) R1)

So first in R1 we get what Specialty the Thesis is in (This is where Mulki's answer helps)
Then in R2 we get the Teachers that are Supervisors
Finally we join R2 and R1 on the condition that they have the same Jury_ID and Specialty
and project their IDs & Names only

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜