{ "data": { "question": { "questionId": "1135", "questionFrontendId": "1045", "boundTopicId": null, "title": "Customers Who Bought All Products", "titleSlug": "customers-who-bought-all-products", "content": "

Table: Customer

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| customer_id | int     |\n| product_key | int     |\n+-------------+---------+\nThis table may contain duplicates rows. \ncustomer_id is not NULL.\nproduct_key is a foreign key (reference column) to Product table.\n
\n\n

 

\n\n

Table: Product

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_key | int     |\n+-------------+---------+\nproduct_key is the primary key (column with unique values) for this table.\n
\n\n

 

\n\n

Write a solution to report the customer ids from the Customer table that bought all the products in the Product table.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nCustomer table:\n+-------------+-------------+\n| customer_id | product_key |\n+-------------+-------------+\n| 1           | 5           |\n| 2           | 6           |\n| 3           | 5           |\n| 3           | 6           |\n| 1           | 6           |\n+-------------+-------------+\nProduct table:\n+-------------+\n| product_key |\n+-------------+\n| 5           |\n| 6           |\n+-------------+\nOutput: \n+-------------+\n| customer_id |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\nExplanation: \nThe customers who bought all the products (5 and 6) are customers with IDs 1 and 3.\n
\n", "translatedTitle": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Medium", "likes": 590, "dislikes": 58, "isLiked": null, "similarQuestions": "[]", "exampleTestcases": "{\"headers\":{\"Customer\":[\"customer_id\",\"product_key\"],\"Product\":[\"product_key\"]},\"rows\":{\"Customer\":[[1,5],[2,6],[3,5],[3,6],[1,6]],\"Product\":[[5],[6]]}}", "categoryTitle": "Database", "contributors": [], "topicTags": [ { "name": "Database", "slug": "database", "translatedName": null, "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below\n", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */\n", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */\n", "__typename": "CodeSnippetNode" }, { "lang": "Pandas", "langSlug": "pythondata", "code": "import pandas as pd\n\ndef find_customers(customer: pd.DataFrame, product: pd.DataFrame) -> pd.DataFrame:\n ", "__typename": "CodeSnippetNode" }, { "lang": "PostgreSQL", "langSlug": "postgresql", "code": "-- Write your PostgreSQL query statement below\n", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"105.3K\", \"totalSubmission\": \"171.7K\", \"totalAcceptedRaw\": 105271, \"totalSubmissionRaw\": 171696, \"acRate\": \"61.3%\"}", "hints": [], "solution": { "id": "1615", "canSeeDetail": false, "paidOnly": true, "hasVideoSolution": false, "paidOnlyVideo": true, "__typename": "ArticleNode" }, "status": null, "sampleTestCase": "{\"headers\":{\"Customer\":[\"customer_id\",\"product_key\"],\"Product\":[\"product_key\"]},\"rows\":{\"Customer\":[[1,5],[2,6],[3,5],[3,6],[1,6]],\"Product\":[[5],[6]]}}", "metaData": "{\"mysql\": [\"Create table If Not Exists Customer (customer_id int, product_key int)\", \"Create table Product (product_key int)\"], \"mssql\": [\"Create table Customer (customer_id int, product_key int)\", \"Create table Product (product_key int)\"], \"oraclesql\": [\"Create table Customer (customer_id int, product_key int)\", \"Create table Product (product_key int)\"], \"database\": true, \"name\": \"find_customers\", \"pythondata\": [\"Customer = pd.DataFrame([], columns=['customer_id', 'product_key']).astype({'customer_id':'Int64', 'product_key':'Int64'})\", \"Product = pd.DataFrame([], columns=['product_key']).astype({'product_key':'Int64'})\"], \"postgresql\": [\"Create table If Not Exists Customer (customer_id int, product_key int)\\n\", \"Create table Product (product_key int)\"], \"database_schema\": {\"Customer\": {\"customer_id\": \"INT\", \"product_key\": \"INT\"}, \"Product\": {\"product_key\": \"INT\"}}}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists Customer (customer_id int, product_key int)", "Create table Product (product_key int)", "Truncate table Customer", "insert into Customer (customer_id, product_key) values ('1', '5')", "insert into Customer (customer_id, product_key) values ('2', '6')", "insert into Customer (customer_id, product_key) values ('3', '5')", "insert into Customer (customer_id, product_key) values ('3', '6')", "insert into Customer (customer_id, product_key) values ('1', '6')", "Truncate table Product", "insert into Product (product_key) values ('5')", "insert into Product (product_key) values ('6')" ], "enableRunCode": true, "enableTestMode": false, "enableDebugger": false, "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }