MySQL Query Provide the SQL statements for each query. The table schema has been
ID: 3754039 • Letter: M
Question
MySQL Query
Provide the SQL statements for each query. The table schema has been given:
Problem 2:
a. The courses for which there are no grades.
b. The numbers (SNO) and names (SNAME) of students having no scores at all (NULL
score value is considered as no score).
c. The possible names of Miss U. Smith's boyfriend. We know that he has taken every
course that was taken by Miss Smith.
Explanation / Answer
(a)
select CNO,CNAME from COURSES
where CNO not in( select distinct CNO from RESULT );
(b)
select SNO,SNAME from STUDENT
where SNO not in (select distinct SNO from RESULT where SCORE is not null);
(c)
Query:
select SNO,SNAME from STUDENT where SNO in(
select r2.SNO from (select r1.SNO,r1.CNO,r2.SNO from RESULT r1,RESULT r2 where r1.CNO = r2.CNO and r1.SNO != r2.SNO and r1.SNO=(select SNO from STUDENT where SNAME = 'U. Smith'))
group by r2.SNO having count(r1.CNO)=(select count(CNO) from RESULT where SNO = (select SNO from STUDENT where SNAME = 'U. Smith'))
);
If you have any doubt then you can ask.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.