P粉7998853112023-08-31 10:19:18
This is my method
step 1: Create a table with two columns, student1 and student2, containing unique combinations of students
For example:
RNO1 RNO2 1 2 1 3 2 3
Step 2: Create a table adding a unique DeptId
for each different DeptId from the previous tableFor example:
RNO1 RNO2 DeptId 1 2 IME 1 2 CHE 1 2 ECO 1 3 IME 1 3 CHE 2 3 ECO
Step 3: Finally, only the tuples in which RNO1 and RNO2 have taken the same course in each DeptId are retained.
The following is an example where rno1_rno2_deptid refers to the table above
SELECT
*
FROM
rno1_rno2_deptid as d
WHERE
NOT EXISTS((SELECT DISTINCT CNO FROM Register AS r WHERE r.RNO = d.RNO1 AND r.DeptId = d.DeptId)
MINUS
(SELECT DISTINCT CNO FROM Register AS r WHERE r.RNO = d.RNO2 AND r.DeptId = d.DeptId))
The above only selects the case where RNO1 and RNO2 have the same CNO in the same series.