考试报名
考试报名
考试内容
考试大纲
在线客服
返回顶部

备考刷题,请到

CDA认证小程序

分数表scores设计如下:courseID(课程编号)studentID(学生编号)score(分数)另有一个学生信息表student,包含studentID,sname(学生姓名)。已知并非所有学生都参加了courseID为0001的考试,现在查询所有参加0001号课程考试及格学生的学生姓名,下面正确的是()
A. select sname from student where studentID in (select studentID from scores where courseID = 0001 and score>=60)
B.  select sname from student where studentID = (select studentID from scores where courseID = 0001 and score>=60)
C.  select sname from student where studentID not in (select studentID from scores where courseID = 0001 and score<=60)
D.  select sname from student where studentID exists (select studentID from scores where courseID = 0001 and score>=60)
上一题
下一题
收藏
点赞
评论
题目解析
题目评论(0)

正确答案是:A: `select sname from student where studentID in (select studentID from scores where courseID = 0001 and score>=60)`

分析如下:

A: 该选项使用了子查询,首先从 `scores` 表中选择参加课程编号为0001且成绩大于等于60的学生编号,然后在 `student` 表中查找这些学生的姓名。这是一个正确的查询方式,可以准确找到所有参加0001号课程并且考试及格的学生姓名。

B: 该选项使用了单值子查询(即等号`=`),这意味着子查询只能返回一个值。如果子查询返回多个学生ID,SQL会报错。因此,这种方式不适用于查找多个符合条件的记录。

C: 该选项试图通过查找不及格的学生ID并排除他们来找到及格学生的姓名。然而,这种方法可能会导致错误,因为如果一个学生没有参加考试,他的记录不会出现在 `scores` 表中,这可能会导致该学生被错误地排除。

D: 该选项语法错误,`exists` 关键字的用法不正确。`exists` 通常用于检查子查询是否返回任何记录,而不是直接在 `where` 子句中使用 `studentID exists`。正确的用法应该是 `where exists (select ... where ...)`,并且需要关联外部查询和子查询。

因此,选项A是正确的查询方式。