0
Follow
0
View

To find out which courses are not taken by students, list the course number and course name.(

aidalaohuyou 注册会员
2023-02-26 17:20

Part of the answer refers to GPT, GPT_Pro better solution
Query which courses are not taken by students, list the course number and course name, can use external link method, External join is to connect some common fields in two tables to realize associated query between two tables. That is, use the LEFT JOIN keyword in the SQL statement to join two tables. In this case, we need to connect the Course table with the SC table first, and then query the Course number and course name that no student chose in the course table according to the fact that Sno column in the SC table does not have a record. The code is as follows:

SELECT C.Cno, C.Cname 
FROM Course C LEFT JOIN SC S ON C.Cno = S.Cno 
WHERE S.Cno IS NULL;
In the SQL statement above, we use the LEFT JOIN keyword to join the Course table and SC table; Then, according to the case that Sno column in SC table does not have a record(that IS, sc. Cno IS NULL), the Course number and course name selected by no students in the course table are queried. After running the above SQL statement, you will get the desired result.
If the answer is helpful, please accept it.
ddk35785 注册会员
2023-02-26 17:20

the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > outer connection(left join) in the query, the left table(that is, the course table) of all records will be retained, Even if there is no matching record in the right table(that is, the sc table). If there is no matching record in the right table, the corresponding field in the left table is filled with null. Therefore, we can use "where sc.cno is null" in the query to get all the courses that were not selected by the student, that is, the left table records that have no matching records in the right table.

About the Author

Question Info

Publish Time
2023-02-26 17:20
Update Time
2023-02-26 17:20

Related Question