sql语句

MySql 码拜 8年前 (2016-02-17) 1753次浏览
学生表(学生id,姓名,年龄,性别,系,地址,出生地)
S(Sid, SNAME, AGE, SEX, DEPARTMENT, ADDRESS, BIRTHPLACE)
选课表(学生id,课程id,成绩)
SC(Sid, Cid, GRADE)
课程表(课程id,课程名,教师id)
C(Cid, CNAME, Tid)
教师表(教师id, 姓名,性别,年龄)
T(Tid,NAME,SEX,AGE)
1.全部成绩都在80分以上的学生姓名及所在系;
select  S1.SNAME ,S1.DEPARTMENT from SC as SC1 left join S as S1 on SC1.Sid=S1.Sid  and  SC1.GRADE >85
2.没有选修“操作系统”课的学生的姓名;
select SNAME from S where Sid not in (select SC1.Sid from SC as SC1 left join C as C1 on SC1.Cid =C1.Cid and C1.CNAME=”操作系统”)
3.英语成绩比数学成绩好的学生;
selcet S1.SNAME from S as S1 where S1.Sid in (select Sid from SC as SC1,SC as SC2 where SC1.GRADE>SC2.GRADE and SC1.Cid in(Select Cid from SC where CNAME=”英语”) and SC2.Cid=( Select Cid from SC where CNAME=”数学”) ) ”
4.选修同一门课程时,女生比男生成绩好的学生名单;
select S1.SNAME from S as S1 left join SC as SC on S1.Sid=SC1.Sid and S1.SEX=”女” and SC1.GRADE>ALL(select SC2.GRADE from S as S2 left join SC as SC2 on S2.Sid=SC2.Sid and S2.SEX=”男” and SC2.Cid=SC1.Cid )
5.至少选修两门以上课程的学生姓名、性别;
select SNAME,SEX from S left join SC on S.Sid=SC.Sid group by SC.Cid count(*)>=2
6.选修了李微微老师所讲课程的学生人数;
Select count(*) from S where Sid in(select dist S1.Sid from S as S1 left join SC as SC1 on S1.Cid=SC1.Cid and SC1.Tid=”李微微”)
7.没有选修李微微老师所讲课程的学生;
select SNAME from S where Sid not in (select dist S1.Sid from S as S1 left join SC as SC1 on S1.Cid=SC1.Cid and SC1.Tid=”李微微”)
8.“操作系统”课程得最高分的学生姓名、性别、所在系;
select S1.SNAME,S1.SEX,S1.DEAPARTMENT from C as C1 left join SC as SC1 on C1.Cid=SC1.Cid and C1.CNAME=”操作系统”and SC1.GRADE in (select MAX(GRADE) from SC1 left join C1 on SC1.Cid=C1.Cid and C1.CNAME=”操作系统” ) left join S as S1 on S1.Sid=SC1.Sid
解决方案

10

谢谢分享sql语句

10

多谢LZ,很不错的基础知识

20

你们怎么不帮他找下错误?sql语句

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明sql语句
喜欢 (0)
[1034331897@qq.com]
分享 (0)