我正在努力解决这个问题,但我不能走得太远。
问题是:
“找到一对名字(重命名为name1和name2),其中每个name1与name2在同一部电影中扮演角色,但在拍摄的电影中获得了更多的报酬。”
Acted In表格是:
ActedIn (name:varchar, title:varchar, year:int, pay:real)
到目前为止,我的查询是:
SELECT B.name FROM ActedIn B WHERE B.title IN (
SELECT A.title FROM ActedIn A GROUP BY A.title HAVING COUNT(*) = 2);
这会返回:(没有标题和付费列,这很好 - 我只是把它包括在内,所以你可以看到)
+---------------+--------------+
| name | title | EXAMPLE PAY |
+------+--------+--------------+
| Dino | movie1 | 500.25 |
+------+--------+--------------+
| Miro | movie1 | 40.15 |
+------+--------+--------------+
| Tino | movie2 | 90.15 |
+------+--------+--------------+
| Kiko | movie2 | 3422.24 |
+------+--------+--------------+
| Bino | movie3 | 653.00 |
+------+--------+--------------+
| Kiko | movie3 | 245.52 |
+------+--------+--------------+
现在我需要以某种方式比较每个电影标题中的演员对,并仅返回其中actor1的薪酬高于演员2的对。
在我上面提供的案例中,所述查询的结果应为:
Dino, Miro in Movie1
Bino, Kiko in Movie3
谢谢!
答案 0 :(得分:2)
select x.name as name1, y.name as name2, x.title as movie
from actedin x join actedin y on x.title = y.title
where x.example_pay > y.example_pay