GROUP BY a.title ORDER BY COUNT(t.song) DESC;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- 显示电影id=1中演员名单
SELECT a.* FROM actor a,casting c
WHERE a.id=c.actorid AND c.movieid=1
-- 显示电影'Alien'中演员名单
SELECT a.* FROM actor a,casting c ,movie m
WHERE a.id=c.actorid AND m.id=c.movieid AND m.title='Alien';
-- 显示有'Harrison Ford'参演的电影名称
SELECT m.title FROM actor a,casting c ,movie m
WHERE a.id=c.actorid AND m.id=c.movieid AND a.NAME='Harrison Ford';
-- 显示有'Harrison Ford'参演的电影名称,但'Harrison Ford'角色排名不是第一
SELECT m.title FROM actor a,casting c ,movie m
WHERE a.id=c.actorid AND m.id=c.movieid AND a.NAME='Harrison Ford' AND c.movieord !=1;
-- 显示1962年发行的电影,及该影片的主角(排名第一)
SELECT m.title ,a.NAME FROM actor a,casting c ,movie m
WHERE a.id=c.actorid AND m.id=c.movieid AND m.yr=1962 AND c.movieord=1;
-- 显示'John Travolta'每年出演的电影数量
SELECT m.yr,COUNT(m.id) FROM actor a,casting c ,movie m
WHERE a.id=c.actorid AND m.id=c.movieid AND a.NAME='John Travolta' GROUP BY m.yr;
-- 列出'Julie Andrews'参演的所有电影名称以及该片的主角
SELECT m.title,a.NAME FROM actor a,casting c ,movie m
WHERE a.id=c.actorid AND m.id=c.movieid AND m.id IN(
SELECT m1.id FROM casting c1,movie m1,actor a1 WHERE m1.id=c1.movieid AND
a1.id=c1.actorid AND a1.NAME='Julie Andrews'
) AND c.movieord=1;
-- 列出在10部电影中出任过主角的演员
SELECT a.NAME FROM actor a,casting c ,movie m WHERE a.id=c.actorid AND m.id=c.movieid
AND c.movieord=1
GROUP BY a.NAME HAVING COUNT(m.title)=10
-- 按演员人数的多少依次列出1978的电影以及演员数。
SELECT m.title ,COUNT(a.NAME) FROM actor a,casting c ,movie m WHERE a.id=c.actorid AND m.id=c.movieid
AND m.yr=1978 GROUP BY m.title ORDER BY COUNT(a.NAME) DESC;
-- 列出所有和'Art Garfunkel'合作过的演员
SELECT DISTINCT a.NAME FROM actor a,casting c ,movie m WHERE a.id=c.actorid AND m.id=c.movieid
AND m.id IN(
SELECT c1.movieid FROM actor a1,casting c1 WHERE a1.id=c1.actorid AND a1.NAME='Art Garfunkel'
)AND a.NAME !='Art Garfunkel';