--含数据库 --1、查询"1"课程比"2"课程成绩高的所有学生的学号; select d.S# from (select b.S#,b.score as b_score,c.score as c_score from (select S#,score from Sc WHERE C#=1) b inner join (select S#,score from Sc WHERE C#=2) c on b.S#=c.S#) d where d.b_score>d.c_score --2、查询平均成绩大于60分的学号和平均成绩; select S#,AVG(score) from Sc Group by S# having AVG(score)>60 --3、查询所有同学的学号、姓名、选课数、总成绩; SELECT a.*, CASE WHEN Num IS null THEN 0 ELSE Num END AS '课程总数', CASE WHEN Total IS NULL THEN 0 ELSE Total END AS '总成绩' FROM (select S#,S name from Student) a left join (select S#,COUNT(*) AS Num,SUM(score) as Total from Sc Group BY S#) b --找所有同学的选课数和总成绩 on a.S#=b.S# --4、查询姓"李"的老师个数; select COUNT(*) from Teacher where Tname LIKE '李%' --5、查询没学过"叶平"老师课的同学的学号、姓名; --(把学过学生的学号先找出来) SELECT d.* FROM Student d left join ( select distinct a.S# from Sc a inner join (select C# from Course where T#= (select T# from Teacher where Tname='叶平')) b on a.C#=b.C# ) c on c.S#=d.S# where c.S# is null --6、查询学过"1"并且也学过编号"2"课程的同学的学号、姓名; name from Student) a left join (select S#,COUNT(*) AS Num,SUM(score) as Total from Sc Group BY S#) b --找所有同学的选课数和总成绩 on a.S#=b.S# --4、查询姓"李"的老师个数; select COUNT(*) from Teacher where Tname LIKE '李%' --5、查询没学过"叶平"老师课的同学的学号、姓名; --(把学过学生的学号先找出来) SELECT d.* FROM Student d left join ( select distinct a.S# from Sc a inner join (select C# from Course where T#= (select T# from Teacher where Tname='叶平')) b on a.C#=b.C# ) c on c.S#=d.S# where c.S# is null --6、查询学过"1"并且也学过编号"2"课程的同学的学号、姓名;