First, query student ids who took exams from table sc: select sid from sc;
Then as the second step, filter for ids not in the result of step 1 in the student table, to find students who did not take exams. So it first retrieves student ids who took exams from table sc, and uses that as a subquery condition to filter for ids not in that result set, in order to find students who did not take any exams.
正确答案是:B: select sname from student where sid not in (select sid from sc);
专业分析如下:
题目要求找出没有参加考试的学生。我们需要从 `student` 表中筛选出那些没有在 `sc` 表中出现过的学生(即没有记录的学生)。
首先,我们来分析各个选项:
- A: `select sname from student where sid in (select sid from sc);`
- 这个查询语句的意思是:从 `student` 表中选出那些在 `sc` 表中出现过的学生。这与题目的要求正好相反,因为它找的是参加了考试的学生。
- B: `select sname from student where sid not in (select sid from sc);`
- 这个查询语句的意思是:从 `student` 表中选出那些在 `sc` 表中没有出现过的学生。这正好符合题目的要求,找出没有参加考试的学生。
- C: `select sname from student;`
- 这个查询语句的意思是:从 `student` 表中选出所有学生。这并没有筛选出没有参加考试的学生,所以不符合题目的要求。
- D: `select sid from sc;`
- 这个查询语句的意思是:从 `sc` 表中选出所有学生的学号。这只是列出了参加考试的学生学号,并没有筛选出没有参加考试的学生,也不符合题目的要求。
综上所述,正确答案是 B。