首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求大神指导,sql查询语句有关问题

2013-02-20 
求大神指导,sql查询语句问题有下列表class(班级表):classno(primary key), classnamestudent(学生表):stun

求大神指导,sql查询语句问题
有下列表
class(班级表):
classno(primary key), classname

student(学生表):
stuno(primary key), stuname, score , classno


1、列出'李明'所在班级中每个学生的姓名与班级号(假设学生没有重名)
             Select stuname,classno From student where classno = (Select classno From student where stuname =’李明’)这是我自己做的,不知道对不对

2、对于student表中的分数至少有2人高于本班级平均水平的班级,列出班级号,学生数,平均分数,按班级号升序排序
求解
3、在student表全体学生中低于自己分数至少有5人的学生,列出其班级号,姓名,分数,以及分数少于自己的人数
求解 没读懂。。
[解决办法]
额。。你的student表分数不包含科目啊。。


--2:
select b.classno,max(stus),max(b.avgs) from student a
inner join 
(select classno,avg(score) avgs,count(*)stus from student group by classno)b
on a.classno=b.classno
where a.score>b.avgs
group by b.classno having count(*)>1
order by b.classno

--3:
select classno,stuname,score,num from (
select *,(select count(*) from student where a.stuno<>stuno and a.score>score) num
from student a 
)b where num>5

热点排行