SQL查询语言

时间:2015-02-28 07:19:09

标签: sql

我会尽量保持这个整洁,因为我有几个问题。

首先,给定这个实体

play(movie, scene, actor)

我想找一些扮演安吉丽娜·朱莉正在演奏的电影演员的名字。这会有用吗

SELECT 
    p.actor
FROM 
    play p
WHERE 
    p.actor NOT LIKE 'Angelina Jolie'
    AND p.movie IN (SELECT p.movie
                    FROM play p
                    WHERE p.actor = 'Angelina Jolie');

第二个问题:我想打印只播放安吉丽娜·朱莉正在播放的电影的演员的名字。这会有用吗

SELECT 
    p.actor
FROM 
    play p
WHERE 
    p.actor NOT LIKE 'Angelina Jolie'
    AND p.movie = ALL(SELECT p.movie
                      FROM play p
                      WHERE p.actor = 'Angelina Jolie');

现在最后,针对另一个问题,给出以下实体

airline (name, telephone, designator)
flight (name, number, departure, arrival, origin, destination)
airport (name, country, designator)

我想打印一对竞争航空公司的名字。拥有相同路线或具有相同出发地和目的地的航空公司。从航空公司的结果中删除对称性不会与自身竞争。这会有用吗

SELECT 
    a1.name, a2.name
FROM 
    airline a1, airline a2, flight f1, flight f2
WHERE 
    a1.name <> a2.name
    AND a1.name = f1.name
    AND a2.name = f2.name
    AND f1.origin = f2.origin
    AND f1.destination = f2.destination
GROUP BY 
    a1.name, a2.name;

然后,打印有飞往泰国所有列出机场的航班的航空公司名称。

SELECT DISTINCT 
    a.name
FROM 
    airline a, flight f
WHERE 
    f.destination = ALL(SELECT a.name
                        FROM airport a
                        WHERE a.country = 'Thailand');

0 个答案:

没有答案