• retagged by
849 views
0 0 votes
Consider the following relations:
STD CHOICES (Student ID, Course ID, Semester) and
COURSE ASSIGN (Teacher ID, Course ID, Semester).
The former indicates the choice of courses for students and
the latter indicates the courses assigned to teachers for different semesters. Note that each student may take multiple courses, each teacher can teach multiple courses and each
course can also be taught by multiple teachers.
Write the relational calculus/algebra/sql query(all three) expression to output the ID
for all the students who have not been taught by the same
teacher in more than one course across all semesters.

1 Answer

0 0 votes

Note that each student may take multiple
courses, each teacher can teach multiple courses and each
course can also be taught by
multiple teachers.
Write the relational calculus expression to output the ID
for all the students who have not been taught by the same
teacher in more than one course across all semesters.

STD CHOICES

COURSE ASSIGN

 

Student ID

Course ID

Semester

Teacher ID

Course ID

Semester

 

1

1

1

1

1

1

 

1

2

1

1

2

1

 

1

3

1

1

3

1

 

2

1

1

2

1

1

 

2

2

1

2

2

1

 

2

3

1

2

3

1

 

1

1

2

1

1

2

 

1

2

2

1

2

2

 

1

3

2

1

3

2

 

2

1

2

2

1

2

 

2

2

2

2

2

2

 

2

3

2

2

3

2

 

3

4

1

3

4

1

 

 

SELECT T2.TeacherID, T1.[StudentID], T1.[CourseID]
FROM [dbo].[STDCHOICES] T1, [dbo].[COURSEASSIGN] T2 
group by T2.TeacherID, T1.[StudentID], T1.[CourseID] 
having count(T2.CourseID)=1 and count(T2.TeacherID) =1

Our Expected student Id should be Student Id=4.  As here each teacher can teach multiple courses and each course can also be taught by multiple teachers thus Relation COURSE ASSIGN

Teacher ID 1 and 2 will not be considered because they taught more than one subject through all semester. Only Teacher ID 4 will be considering. Please correct me if I am wrong.

Position:
Show:

Related questions

0 0 votes
0 0 answers
404
404 views
kapilkant yadav asked Apr 30, 2018
404 views
Consider the following relations:STD CHOICES (Student ID, Course ID, Semester) andCOURSE ASSIGN (Teacher ID, Course ID, Semester).The former indicates the choice of cours...
0 0 votes
0 0 answers
345
345 views
admin asked Aug 8, 2022
345 views
Consider two $n \times 1$ vectors u and v, stored as tables $\mathrm{U(ind, val)}$ and $\mathrm{V(ind, val)}$ with the same schema. A row $\left(i, u_{i}\right)$ of tabl...
0 0 votes
2 2 answers
1.1k
1.1k views
Devasish Ghosh asked Mar 2, 2017
1,130 views
Commodity items have some positive or negative changes in theirprices each week. Each trading company picks a portfolio of com-modity items, that is, they have one or mor...
1 1 vote
0 0 answers
1.6k
1.6k views
shivanisrivarshini asked Mar 20, 2018
1,583 views
Consider the following relational schema:$\text{DOCTOR}(\textit{DoctorName}, \textbf{RegistrationNumber}$)$\text{PATIENT}(\textbf{PatientID}, \textit{PatientName})$$\text...