当前位置: 代码迷 >> 综合 >> sql 中关于 in 子语句查询的理解
  详细解决方案

sql 中关于 in 子语句查询的理解

热度:58   发布时间:2024-02-19 17:57:19.0
USE School;#请在此处添加实现代码
########## Begin ###########1.查询表中至少有两门课程在90分以上的学生信息
select sno,count(*) from tb_grade where score>=90 group by sno having count(*)>=2;#2.查询表中平均成绩大于90分且语文课在95分以上的学生信息
select sno,avg(score) from tb_grade where sno in (select sno from tb_grade where score>=95 and pno='语文') group by sno having avg(score)>=90;########## End #########

第二句中不能改成

select position,salary from tb_salary where score>=95 and pno = "语文";该语句意义与in代码中不同。后者以sno的值作为限制条件,而前者缩小了范围,导致结果出错。

  相关解决方案