retagged by
1,477 views
3 votes
3 votes

Consider the following schema:
Student (Sid, Sname, age)
Course Info (Cid, Cname, Instructor SSN)
Enroll (Sid, Cid, grade).

The relational algebra expression for “find the Cid’s of courses enrolled by two different students” is ??

retagged by

1 Answer

0 votes
0 votes

Student (Sid, Sname, age)
Course Info (Cid, Cname, Instructor SSN)
Enroll (Sid, Cid, grade)

The relational algebra expression for “find the Cid’s of courses enrolled by two different students” :

1. “find the Cid’s of courses enrolled by at least two (different) students” :

$E_1(S,C,G) \leftarrow Enroll$ // Renaming of enroll relation into E_1 with attributes names as $S,C,G$ in that order.

$At\_least2 \leftarrow \prod_{cid} (E_1 \Join_{(C = Cid \, \wedge \,S \neq Sid)} Enroll)$ //Finding courses which have at least two students.

2. “find the Cid’s of courses enrolled by at least three (different) students” :

Similar to what we did in the previous query. 

$E_1(S1,C1,G1) \leftarrow Enroll$ // Renaming of enroll relation into E_1 with attributes names as $S1,C1,G1$ in that order.

$E_2(S2,C2,G2) \leftarrow Enroll$ // Renaming of enroll relation into E_2 with attributes names as $S2,C2,G2$ in that order.

$At\_least3 \leftarrow \prod_{cid} ( (E_1 \Join_{(C = Cid \, \wedge \,S \neq Sid)} Enroll) \,\, \Join_{(C2 = C1 \, \wedge \, S2 \neq S1 \, \wedge \, S2 \neq Sid)} E_2  )$ //Finding courses which have at least three students.

3. “find the Cid’s of courses enrolled by exactly two (different) students” :

$Exactly2 \leftarrow At\_least2 - At\_least3$

 

 

edited by

Related questions

0 votes
0 votes
1 answer
1
Ashutosh_17 asked Mar 30, 2023
789 views
Let R be a relation of degree 5 then the total number of projections possible on R is ___?
3 votes
3 votes
1 answer
4
Hirak asked May 25, 2019
2,087 views
In a relational algebra ∩ is not a basic operator, to make it basic only relational operator we should have areX, – X, UU, –