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);
專業(yè)分析如下:
題目要求找出沒有參加考試的學(xué)生。我們需要從 `student` 表中篩選出那些沒有在 `sc` 表中出現(xiàn)過的學(xué)生(即沒有記錄的學(xué)生)。
首先,我們來分析各個選項(xiàng):
- A: `select sname from student where sid in (select sid from sc);`
- 這個查詢語句的意思是:從 `student` 表中選出那些在 `sc` 表中出現(xiàn)過的學(xué)生。這與題目的要求正好相反,因?yàn)樗业氖菂⒓恿丝荚嚨膶W(xué)生。
- B: `select sname from student where sid not in (select sid from sc);`
- 這個查詢語句的意思是:從 `student` 表中選出那些在 `sc` 表中沒有出現(xiàn)過的學(xué)生。這正好符合題目的要求,找出沒有參加考試的學(xué)生。
- C: `select sname from student;`
- 這個查詢語句的意思是:從 `student` 表中選出所有學(xué)生。這并沒有篩選出沒有參加考試的學(xué)生,所以不符合題目的要求。
- D: `select sid from sc;`
- 這個查詢語句的意思是:從 `sc` 表中選出所有學(xué)生的學(xué)號。這只是列出了參加考試的學(xué)生學(xué)號,并沒有篩選出沒有參加考試的學(xué)生,也不符合題目的要求。
綜上所述,正確答案是 B。