javaSql面试题(10题)
作者:互联网
有如下四张表:
学生表Student(stuId,stuName,stuAge,stuSex);
课程表Course(courseId,courseName,teacherId);
成绩表Scores(stuId,courseId,score);
教师表Teacher(teacherId,teacherName);
有如下10个问题:
查询“001”课程比“002”课程成绩高的所有学生的学号
select stuId
from Scores s1,Scores s2
where
s1.stuId=s2.stuId and s1.courseId="001" and s2.courseId="002" and s1.score>s2.score;
此题是一个自连接查询,也就是两个表都是同一张表。查询平均成绩大于60分的同学的学号和平均成绩
select Student.stuId,avg(Scores.score)
from Student,Scroes
where Studen.stuId=Scores.stuId
Group by Student.stuId
having avg(Scores.score)>60;
聚合函数是不能连接在where子句后面的。- 查询所有同学的学号,姓名,选课数,总成绩
select Student.stuId,Student.stuName,count(Course.courseId),sum(Scores.score)
from Student,Course,Scores
where Studend.stuId=Scores.stuId and Scores.courseId=Course.courseId - 查询姓李的老师的个数
select count(Teacher.TeacherId)
from Teacher
where Teacher.TeacherName like "李%";
标签:10,面试题,score,courseId,where,javaSql,Student,Scores,stuId 来源: https://www.cnblogs.com/jasonboren/p/11121975.html