首页 > 试题广场 >

Mysql中表student_table(id,name,b

[单选题]
Mysql中表student_table(id,name,birth,sex),score_table(stu_id,subject_name,score),查询没有英语分数的学生明细记录,如下SQL正确的是()?
  • select * from student_table  where id  in (
    select stu_id from score_table where subject_name <> '英语');
  • select * from student_table  where id not in (
    select stu_id from score_table where subject_name = '英语');
  • select * from student_table  where id not in (
    select stu_id from score_table where subject_name <> '英语');
  • select * from student_table  where id  in (
    select stu_id from score_table where subject_name = '英语');
假设得分表如下:
张三  语文  95
张三  数学 75
张三  英语 86
李四   语文  89
A选项:子查询科目字段不等于英语,就把张三和李四的id都选出来 所以错了
B选项: 子查询科目字段等于英语,就把张三选出来了,NOT IN 就剩下李四,所以选这个
发表于 2021-12-25 17:53:26 回复(5)
如果该学生id = 1,subject_name is NULL, score is NULL
A选项:查询结果会忽略值为NULL的数据。
B选项:可以查询出除subject_name = ‘英语’的所有情况。
发表于 2021-12-14 10:31:54 回复(0)
反应不过来的话,可以大致写出这个分数表见下:,假设表中01学生没有英语分数,那么子查询的结果应该是输出01,对于A选项,查询结果是01,02,03,所以错误,对于B选项,查询结果是01。
id   name score
02   英语    98
03   英语    22
01   数学    44
02   数学    44
03   数学    44
发表于 2022-06-13 09:36:28 回复(0)
考了英语的也会考别的,查不等于英语的查不全
发表于 2021-12-21 22:24:59 回复(0)
还有考了英语但是英语成绩为null的情况。
发表于 2022-01-10 17:16:06 回复(1)
有学生没考英语,故b对a错
发表于 2021-12-13 21:38:42 回复(0)
开始没有读懂题,看了大家的答案才明白题在问:查询没有考英语的同学。 子查询为选择考了英语的同学,not in除去这些同学 则为没有考英语的同学。
发表于 2022-04-03 13:22:37 回复(0)
A选项,子查询是得到科目不等于英语的id,如果没有英语的id有其他科目,那么他的id仍然会被包含,该查询没有任何意义
发表于 2023-10-14 10:32:39 回复(0)