The relational schema:
MOVIE(TITLE,DIRECTOR,YEAR) CAST(TITLE,ACTOR)
Queries:
SELECT C1.ACTOR FROM CAST C1, CAST C2 WHERE C1.TITLE='Star Wars' AND C2.TITLE='Return of Jedi' AND C1.ACTOR=C2.ACTOR AND NOT EXISTS (SELECT * FROM CAST C3 WHERE C3.ACTOR=C1.ACTOR AND C3.TITLE<>'Star Wars' AND C3.TITLE<>'Return of Jedi')
CREATE VIEW MA(T,D,Y,A) AS SELECT M.TITLE,M.DIRECTOR,M.YEAR,C.ACTOR FROM MOVIE M, CAST C WHERE M.TITLE=C.TITLE; CREATE VIEW MY(A,C) AS SELECT A, COUNT(*) FROM MA GROUP BY A,Y; SELECT A, MAX(C) FROM MY GROUP BY A;
CREATE VIEW CAREER(A,S) AS SELECT A, MAX(YEAR)-MIN(YEAR) FROM MA GROUP BY A; SELECT A FROM CAREER WHERE S=(SELECT MAX(S) FROM CAREER);
SELECT ACTOR FROM CAST C WHERE NOT EXISTS (SELECT * FROM MA M1, MA M2 WHERE M1.A=C.A AND M2.A=C.A AND M1.Y-3>M2.Y AND NOT EXISTS (SELECT * FROM MA M3 WHERE M3.A=C.A AND M1.Y>M3.Y AND M3.Y>M2.Y))
CREATE VIEW AD(A,D,CT) AS SELECT A, D, COUNT(TITLE) FROM MA GROUP BY A, D; SELECT A FROM AD T1 WHERE (SELECT CT FROM AD T2 WHERE T2.D='Spielberg' AND T2.A=T1.A) >ALL (SELECT CT FROM AD T2 WHERE T2.D<>'Spielberg' AND T2.A=T1.A)
The relational schema:
EMP(NAME,DEPT,SALARY)
Queries:
CREATE VIEW DS(D,S,C) AS SELECT DEPT,SUM(SALARY),COUNT(*) FROM EMP GROUP BY DEPT; SELECT E.NAME FROM EMP E, DS WHERE E.DEPT=DS.D AND E.SALARY>2*(DS.S/DS.C);
SELECT D FROM DS WHERE D.S>2*(SELECT AVG(S) FROM DS)
SELECT E1.NAME FROM EMP E1 WHERE 99>= (SELECT COUNT(DISTINCT SALARY) FROM EMP E2 WHERE E2.SALARY>E1.SALARY)