mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
41 lines
1.2 KiB
HTML
41 lines
1.2 KiB
HTML
|
<p><code>ActorDirector</code> 表:</p>
|
||
|
|
||
|
<pre>
|
||
|
+-------------+---------+
|
||
|
| Column Name | Type |
|
||
|
+-------------+---------+
|
||
|
| actor_id | int |
|
||
|
| director_id | int |
|
||
|
| timestamp | int |
|
||
|
+-------------+---------+
|
||
|
timestamp 是这张表的主键.
|
||
|
</pre>
|
||
|
|
||
|
<p> </p>
|
||
|
|
||
|
<p>写一条SQL查询语句获取合作过至少三次的演员和导演的 id 对 <code>(actor_id, director_id)</code></p>
|
||
|
|
||
|
<p><strong>示例:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
ActorDirector 表:
|
||
|
+-------------+-------------+-------------+
|
||
|
| actor_id | director_id | timestamp |
|
||
|
+-------------+-------------+-------------+
|
||
|
| 1 | 1 | 0 |
|
||
|
| 1 | 1 | 1 |
|
||
|
| 1 | 1 | 2 |
|
||
|
| 1 | 2 | 3 |
|
||
|
| 1 | 2 | 4 |
|
||
|
| 2 | 1 | 5 |
|
||
|
| 2 | 1 | 6 |
|
||
|
+-------------+-------------+-------------+
|
||
|
|
||
|
Result 表:
|
||
|
+-------------+-------------+
|
||
|
| actor_id | director_id |
|
||
|
+-------------+-------------+
|
||
|
| 1 | 1 |
|
||
|
+-------------+-------------+
|
||
|
唯一的 id 对是 (1, 1),他们恰好合作了 3 次。</pre>
|