mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
68 lines
1.6 KiB
HTML
68 lines
1.6 KiB
HTML
|
<p>Table: <code>Customer</code></p>
|
||
|
|
||
|
<pre>
|
||
|
+-------------+---------+
|
||
|
| Column Name | Type |
|
||
|
+-------------+---------+
|
||
|
| customer_id | int |
|
||
|
| product_key | int |
|
||
|
+-------------+---------+
|
||
|
This table may contain duplicates rows.
|
||
|
<code>customer_id</code> is not NULL<code>.</code>
|
||
|
product_key is a foreign key (reference column) to <code>Product</code> table.
|
||
|
</pre>
|
||
|
|
||
|
<p> </p>
|
||
|
|
||
|
<p>Table: <code>Product</code></p>
|
||
|
|
||
|
<pre>
|
||
|
+-------------+---------+
|
||
|
| Column Name | Type |
|
||
|
+-------------+---------+
|
||
|
| product_key | int |
|
||
|
+-------------+---------+
|
||
|
product_key is the primary key (column with unique values) for this table.
|
||
|
</pre>
|
||
|
|
||
|
<p> </p>
|
||
|
|
||
|
<p>Write a solution to report the customer ids from the <code>Customer</code> table that bought all the products in the <code>Product</code> table.</p>
|
||
|
|
||
|
<p>Return the result table in <strong>any order</strong>.</p>
|
||
|
|
||
|
<p>The result format is in the following example.</p>
|
||
|
|
||
|
<p> </p>
|
||
|
<p><strong class="example">Example 1:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
<strong>Input:</strong>
|
||
|
Customer table:
|
||
|
+-------------+-------------+
|
||
|
| customer_id | product_key |
|
||
|
+-------------+-------------+
|
||
|
| 1 | 5 |
|
||
|
| 2 | 6 |
|
||
|
| 3 | 5 |
|
||
|
| 3 | 6 |
|
||
|
| 1 | 6 |
|
||
|
+-------------+-------------+
|
||
|
Product table:
|
||
|
+-------------+
|
||
|
| product_key |
|
||
|
+-------------+
|
||
|
| 5 |
|
||
|
| 6 |
|
||
|
+-------------+
|
||
|
<strong>Output:</strong>
|
||
|
+-------------+
|
||
|
| customer_id |
|
||
|
+-------------+
|
||
|
| 1 |
|
||
|
| 3 |
|
||
|
+-------------+
|
||
|
<strong>Explanation:</strong>
|
||
|
The customers who bought all the products (5 and 6) are customers with IDs 1 and 3.
|
||
|
</pre>
|