1、数据库习题作业重点(第 2-3-4 章)2.6 设有关系 R 和 S:R A B C S A B C3 6 7 3 4 52 5 7 7 2 37 2 34 4 3计算 RS,R-S,RS,RS, 3,2(S), B10ORDER BY 2 DESC,1;检索学号比 WANG 同学大,而年龄比他小的学生姓名。SELECT SNAMEFROM SWHERE S#ALL(SELECT S# FROM SWHERE SNAME=WANG)AND AGE(SELECT AVG(AGE)FROM SWHERE SEX=F);求年龄大于所有女同学年龄的男学生的姓名和年龄。SELECT SNAME, AGE
2、FROM SWHERE SEX=MAND AGEALL(SELECT AGEFROM SWHERE SEX=F);【312】解:INSERT INTO CVALUES(C8, VC+, T6);法一:INSERT INTO FACULTY(TNAME)SELECT DISTINCT TNAMEFROM (SELECT TNAME,CC# ,AVG(SCORE)FROM T, C, SCWHERE TT#=C T# AND CC#=SC C#GROUP BY TNAME,CC#)AS RESULT(TNAME,C#,AVGSCORE) AS XWHERE 8070;UPDATE SCSET SC
3、ORE=SCORE * 1.05WHERE C#=C4AND SCORE70 THEN 1.04ELSE l.05ENDWHERE C#=C4;UPDATE SCSET SCORE=SCORE * 1.05WHERE SCORE50 AND SEX=M;SELECT EMPE#,ENAMEFROM EMP, WORKSWHERE EMP.E#=WORKSE# AND SALARY1000 AND SEX=M;SELECT AE#,AENAMEFROM EMP A,WORKS B ,WORKS CWHERE AE#=BE# AND B E#=CE#AND BC#=C4 AND CC#=C8 ;S
4、ELECT AE#,AENAMEFROM EMP A,WORKS B ,COMP CWHERE AE#=BE# AND B C#=C #AND CNAME=联华公司 AND SALARY1000 AND SEX=M;SELECT E# ,COUNT(C#) AS NUM,SUM(SALARY) AS SUM_SALARYFROM WORKSGROUP BY E#;SELECT X.E#FROM WORKS XWHERE NOT EXISTS(SELECT *FROM WORKS YWHERE E#=E6AND NOT EXISTS(SELECT *FROM WORKS ZWHERE ZE#=XE# AND ZC#=Y C# );SELECT AE#,AENAME