{ "data": { "question": { "questionId": "586", "questionFrontendId": "586", "categoryTitle": "Database", "boundTopicId": 2642, "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 for this table.\nThis table contains information about the order ID and the customer ID.\n
\n\n

 

\n\n

Write an SQL query 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 query 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": "订单最多的客户", "translatedContent": "

表: Orders

\n\n
\n+-----------------+----------+\n| Column Name     | Type     |\n+-----------------+----------+\n| order_number    | int      |\n| customer_number | int      |\n+-----------------+----------+\nOrder_number是该表的主键。\n此表包含关于订单ID和客户ID的信息。\n
\n\n

 

\n\n

编写一个SQL查询,为下了 最多订单 的客户查找 customer_number

\n\n

测试用例生成后, 恰好有一个客户 比任何其他客户下了更多的订单。

\n\n

查询结果格式如下所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入: \nOrders 表:\n+--------------+-----------------+\n| order_number | customer_number |\n+--------------+-----------------+\n| 1            | 1               |\n| 2            | 2               |\n| 3            | 3               |\n| 4            | 3               |\n+--------------+-----------------+\n输出: \n+-----------------+\n| customer_number |\n+-----------------+\n| 3               |\n+-----------------+\n解释: \ncustomer_number 为 '3' 的顾客有两个订单,比顾客 '1' 或者 '2' 都要多,因为他们只有一个订单。\n所以结果是该顾客的 customer_number ,也就是 3 。\n
\n\n

 

\n\n

进阶: 如果有多位顾客订单数并列最多,你能找到他们所有的 customer_number 吗?

\n", "isPaidOnly": false, "difficulty": "Easy", "likes": 42, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false}", "topicTags": [ { "name": "Database", "slug": "database", "translatedName": "数据库", "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"24.9K\", \"totalSubmission\": \"33.9K\", \"totalAcceptedRaw\": 24887, \"totalSubmissionRaw\": 33914, \"acRate\": \"73.4%\"}", "hints": [ "MySQL uses a different expression to get the first records other than MSSQL's TOP expression." ], "solution": null, "status": null, "sampleTestCase": "{\"headers\":{\"orders\":[\"order_number\",\"customer_number\"]},\"rows\":{\"orders\":[[1,1],[2,2],[3,3],[4,3]]}}", "metaData": "{\n \"mysql\": [\n \"Create table If Not Exists orders (order_number int, customer_number int)\"\n ],\n \"mssql\": [\n \"Create table orders (order_number int, customer_number int)\"\n ],\n \"oraclesql\": [\n \"Create table orders (order_number int, customer_number int)\"\n ],\n \"database\": true\n}", "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, "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"]}", "book": null, "isSubscribed": false, "isDailyQuestion": false, "dailyRecordStatus": null, "editorType": "CKEDITOR", "ugcQuestionId": null, "style": "LEETCODE", "exampleTestcases": "{\"headers\":{\"orders\":[\"order_number\",\"customer_number\"]},\"rows\":{\"orders\":[[1,1],[2,2],[3,3],[4,3]]}}", "__typename": "QuestionNode" } } }