select TNO,TN from T where TN like '_伟%'
select TN from T where TNO='C5'
select T.TNO,T.TN,TC.CNO from T,TC where T.TNO=TC.TNO and T.TN='刘伟'
select TC.TNO,group by TC.CNO as ‘任课数’from TC,T where TC.TNO=T.TNO
and T.Dept='计算机' and T.TNO in (select TNO from TC group by CNO havingcount(*)>2)
selcet TNO,TN from T where Prof in (select Prof from T where TN='刘伟')
select x.TN as姓名,x.Sal as 教师工资, y.Sal as刘伟的工资from T as x,T as y
where x.Sal>y.Sal and y.TN='刘伟'
第四问不太确定
(1)检索计算机系的全体学生的学号,姓名和性别;SELECT SNO,SNAME,SEX FROM S
WHERE SNO IN (
SELECT SNO FROM SC WHERE CNO IN (SELECT SNO FROM C WHERE CDEPT='计算机')
)
(2)检索学习课程号为C2的学生学号与姓名;
SELECT SNO,SNAME FROM S
WHERE SNO IN (SELECT SNO FROM SC WHERE CNO='C2')
(3)检索选修课程名为“DS”的学生学号与姓名;
SELECT SNO,SNAME FROM S
WHERE SNO IN (SELECT SNO FROM SC WHERE CNO IN (SELECT CNO FROM C WHERE CNAME='DS'))
(4)检索选修课程号为C2或C4的学生学号;
SELECT SNO FROM SC WHERE CNO IN ('C2','C4')
(5)检索至少选修课程号为C2和C4的学生学号;
SELECT SNO FROM S
WHERE SNO IN (SELECT SNO FROM SC WHERE CNO='C2')
AND SNO IN (SELECT SNO FROM SC WHERE CNO='C4')
(6)检索不学C2课的学生姓名和年龄;
SELECT SNAME,AGE FROM S
WHERE SNO NOT IN (SELECT SNO FROM SC WHERE CNO='C2')
AND SNO NOT IN (SELECT SNO FROM SC WHERE CNO='C4')
(7)检索学习全部课程的学生姓名;
SELECT SNAME FROM S
WHERE SNO IN (
SELECT SNO FROM SC WHERE NOT EXISTS (SELECT * FROM C WHERE SC.CNO=C.CNO)
)
(8)查询所学课程包含学生S3所学课程的学生学号。
SELECT SNAME FROM S
WHERE SNO IN (
SELECT SNO FROM SC WHERE NOT EXISTS (SELECT * FROM SC SC2 WHERE SC2.CNO=SC.CNO)
)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)