sql - Difficult oracle query -
i have database looks this:
table_students: { studentid(pk), name }; table_stu_cou:{ studentid(fk), courseid(fk) }; table_courses:{ courseid(pk), coursename }; table_tea_cou { courseid(fk), teacherid(fk) }; table_teachers:{ teacherid(pk), name};
the stu_cou table shows students attend courses. tea_cou tables shows teachers teach course. have list students , teachers have never met (the student has never attended course presented lecturer). can't figure out how make , i've been trying 2 days. me? i'm using oracle.
what need first compute potential pairs student,teacher, subtract student teachers have met:
the first done crossproduct of students , teachers. second join based on courses have taken:
select studentid, teacherid students, teachers except select studentid, teacherid stu_cou natural join tea_cou;
if interested in student names , teacher names can use result subquery , joins students , teachers tables information. leave exercise do.
--dmg
Comments
Post a Comment