select Cname,count(*) as num
from Course,
(
select *
from SC
where Cno
in(
select Cno
from SC
group by Cno
having Count(*)>50
)
) tempTable
where Course.Cno=tempTable.Cno
group by Course.Cno,Cname
order by num asc
select Table1.Sno
from
(
select sc0.Sno,count(*) as Snum
from sc as sc0
group by sc0.Sno
) as Table1,
(
select STable.Sno,count(*) as maxNum
from
(
select sc1.Sno,sc1.Cno,sc1.Grade
from sc as sc1,
(
select sc2.Cno,max(sc2.Grade) as maxGrade
from sc as sc2
group by sc2.Cno
) as maxTable
where sc1.Cno=maxTable.Cno and sc1.Grade=maxTable.maxGrade
) as STable
group by STable.Sno
) Table2
where Table1.Sno=Table2.Sno and Table1.Snum=Table2.maxNum
--6查询没有选课的学生的学号和姓名
select Student.Sno,Sname
from Student
where Student.Sno not in
(
select distinct Sc.Sno
from SC
)
这么问有些笼统了,不太能够给出具体的SQL语句
首先要看你的数据库结构是什么样子的
如果只有两张表,一张学生信息表和一张学生成绩表,那就根据这两张表的结构设计SQL查询语句,具体需要的信息不同查询语句也不一样。
你如果需要标准的SQL语句的话,建议你给出设计表结构以及需要的查询的信息是什么
select 学生表.学号,学生表.姓名,average(成绩表.成绩) as 平均成绩,
max(成绩表.成绩) as 最高成绩,
min(成绩表.成绩) as 最低成绩
from 学生表 left join 成绩表 on 学生表.学号=成绩表.学号
order by 学生表.学号
成绩表可换成语文、数学、英语等,查询结果就是各个学生相应课程的平均成绩、历史最高成绩、历史最低成绩.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)