{ "data": { "question": { "questionId": "586", "questionFrontendId": "586", "boundTopicId": null, "title": "Customer Placing the Largest Number of Orders", "titleSlug": "customer-placing-the-largest-number-of-orders", "content": "

Table: Orders

\n\n
\n+-----------------+----------+\n| Column Name     | Type     |\n+-----------------+----------+\n| order_number    | int      |\n| customer_number | int      |\n+-----------------+----------+\norder_number is the primary key (column with unique values) for this table.\nThis table contains information about the order ID and the customer ID.\n
\n\n

 

\n\n

Write a solution to find the customer_number for the customer who has placed the largest number of orders.

\n\n

The test cases are generated so that exactly one customer will have placed more orders than any other customer.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nOrders table:\n+--------------+-----------------+\n| order_number | customer_number |\n+--------------+-----------------+\n| 1            | 1               |\n| 2            | 2               |\n| 3            | 3               |\n| 4            | 3               |\n+--------------+-----------------+\nOutput: \n+-----------------+\n| customer_number |\n+-----------------+\n| 3               |\n+-----------------+\nExplanation: \nThe customer with number 3 has two orders, which is greater than either customer 1 or 2 because each of them only has one order. \nSo the result is customer_number 3.\n
\n\n

 

\n

Follow up: What if more than one customer has the largest number of orders, can you find all the customer_number in this case?

\n", "translatedTitle": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Easy", "likes": 925, "dislikes": 68, "isLiked": null, "similarQuestions": "[]", "exampleTestcases": "{\"headers\":{\"orders\":[\"order_number\",\"customer_number\"]},\"rows\":{\"orders\":[[1,1],[2,2],[3,3],[4,3]]}}", "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 largest_orders(orders: pd.DataFrame) -> pd.DataFrame:\n ", "__typename": "CodeSnippetNode" }, { "lang": "PostgreSQL", "langSlug": "postgresql", "code": "-- Write your PostgreSQL query statement below\n", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"222.2K\", \"totalSubmission\": \"341.2K\", \"totalAcceptedRaw\": 222243, \"totalSubmissionRaw\": 341164, \"acRate\": \"65.1%\"}", "hints": [ "MySQL uses a different expression to get the first records other than MSSQL's TOP expression." ], "solution": { "id": "160", "canSeeDetail": false, "paidOnly": true, "hasVideoSolution": false, "paidOnlyVideo": true, "__typename": "ArticleNode" }, "status": null, "sampleTestCase": "{\"headers\":{\"orders\":[\"order_number\",\"customer_number\"]},\"rows\":{\"orders\":[[1,1],[2,2],[3,3],[4,3]]}}", "metaData": "{\"mysql\": [\"Create table If Not Exists orders (order_number int, customer_number int)\"], \"mssql\": [\"Create table orders (order_number int, customer_number int)\"], \"oraclesql\": [\"Create table orders (order_number int, customer_number int)\"], \"database\": true, \"name\": \"largest_orders\", \"pythondata\": [\"orders = pd.DataFrame([], columns=['order_number', 'customer_number']).astype({'order_number':'Int64', 'customer_number':'Int64'})\"], \"postgresql\": [\"Create table If Not Exists orders (order_number int, customer_number int)\"], \"database_schema\": {\"orders\": {\"order_number\": \"INT\", \"customer_number\": \"INT\"}}}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists orders (order_number int, customer_number int)", "Truncate table orders", "insert into orders (order_number, customer_number) values ('1', '1')", "insert into orders (order_number, customer_number) values ('2', '2')", "insert into orders (order_number, customer_number) values ('3', '3')", "insert into orders (order_number, customer_number) values ('4', '3')" ], "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" } } }