- Assign every course a unique bit. For example, course A = 1 (0001), course B = 2 (0010), course C = 4 (0100), etc. Then, for all possible combinations of courses, their sum of the bits are unique.
- Sort and concatenate course IDs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with course_bitmap as ( | |
select | |
Course_ID, | |
power(2, row_number() over (order by course_id) - 1) as course_bit | |
from Course | |
) | |
select | |
sum(cb.course_bit) over (partition by sc.Student_id) as Group_id, | |
sc.Student_id, | |
sc.Course_id | |
from | |
Student_Course sc join course_bitmap cb on | |
sc.Course_ID = cb.Course_ID | |
order by Group_id, Student_ID, Course_ID |
No comments:
Post a Comment