sql面试题

sql面试题

--1.查询平均成绩大于60分的同学的学号和平均成绩
--select StuId,avg(Score) from student group by StuID having avg (Score) > 60;

--2.查询姓“李”的学生的个数(一个学生可能会有多条学科成绩)
--select count(distinct StuID) from student where StuID in (select StuID from student where name like '李%' group by StuID);

--3.查询每个学生的最高分及所属学科(每个学生的最高分只有一科)
--select  s.name,zgf,subject from student t,(select name,max(Score) zgf from student group by name) s where t.score = zgf;

--4.查询每个老师教的各科的平均分
select t.subject, TName,ss.平均成绩 from teacher t,(select subject, avg(Score) 平均成绩 from student group by subject) ss where t.subject = ss.subject

本人小白,复习sql时想到了面试时的几道题,觉得还是颇具难度的,那么找来原题又再认真做了一遍,已经经过查询编辑器验证过,聊作分享,语句不是很规范,那么大家看的时候根据自己的习惯改吧。