How do I find the name of the student who took all the courses? -ms-sqlserver/Application Examples

Source: Internet
Author: User

Check the name of the student who took all the courses
: Student is the student table course is the timetable SC is the timetable
Select Sname
From student
Where NOT EXISTS
(SELECT *
From course
Where NOT EXISTS
(SELECT *
From SC
Where Sno =student.sno
and CNO=COURSE.CNO)
How to explain it? I just JoJo understand, but it is to explain to others do not understand. Hope the master to explain.

------Answer---------

------Other answers (10 points)---------


SELECT *
From course
Where NOT EXISTS
(SELECT *
From SC
Where Sno =student.sno
and CNO=COURSE.CNO)
This section calculates that a student has no selected courses
If the outer layer is added to a course that does not exist, there is no choice. That's the whole choice.

------Other answers (10 points)---------

SQL Code
--From the Inside Out analysis select * FROM Student--(3) Where NOT EXISTS (SELECT * FROM Course--(2) Where NOT EXISTS (SELECT * from S C WHERE Sno=student.sno--(1) and CNO=COURSE.CNO));--(1) Find all courses selected by a student select * from SC where Sno=student.sno--(2) Find this Students do not have elective courses select * FROM course C where NOT exists (SELECT * from SC where sno=student.sno and Cno=course.cno)--(3) Exclude this No Students taking all the courses
------Other answers (4 points)---------


Negative negative is positive, there is no one branch of no elective, that is, each branch elective

How do I find the name of the student who took all the courses? -ms-sqlserver/Application Examples

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.