Использование левого соединения с нулевым тестом
drop table if exists t;
create table t(ID int, STUDENT_ID int, COURSE_ID int, STATUS varchar(20));
insert into t values
(1 , 5 , 12 , 'Enrolled'),
(2 , 5 , 12 , 'In-Progress'),
(3 , 2 , 12 , 'Enrolled'),
(4 , 2 , 12 , 'Completed'),
(5 , 5 , 12 , 'Completed'),
(6 , 2 , 14 , 'Enrolled');
select t.* from t
left join
(select student_id,course_id,count(*) from t where status not in('enrolled','completed') group by student_id,course_id) s
on t.STUDENT_ID = s.student_id and t.course_id = s.course_id
where s.student_id is null;
+------+------------+-----------+-----------+
| ID | STUDENT_ID | COURSE_ID | STATUS |
+------+------------+-----------+-----------+
| 3 | 2 | 12 | Enrolled |
| 4 | 2 | 12 | Completed |
| 6 | 2 | 14 | Enrolled |
+------+------------+-----------+-----------+
3 rows in set (0.00 sec)