{ "data": { "question": { "questionId": "180", "questionFrontendId": "180", "categoryTitle": "Database", "boundTopicId": 1133, "title": "Consecutive Numbers", "titleSlug": "consecutive-numbers", "content": "
Table: Logs
\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| id | int |\n| num | varchar |\n+-------------+---------+\nIn SQL, id is the primary key for this table.\nid is an autoincrement column.\n\n\n
\n\n
Find all numbers that appear at least three times consecutively.
\n\nReturn the result table in any order.
\n\nThe result format is in the following example.
\n\n\n
Example 1:
\n\n\nInput: \nLogs table:\n+----+-----+\n| id | num |\n+----+-----+\n| 1 | 1 |\n| 2 | 1 |\n| 3 | 1 |\n| 4 | 2 |\n| 5 | 1 |\n| 6 | 2 |\n| 7 | 2 |\n+----+-----+\nOutput: \n+-----------------+\n| ConsecutiveNums |\n+-----------------+\n| 1 |\n+-----------------+\nExplanation: 1 is the only number that appears consecutively for at least three times.\n\n", "translatedTitle": "连续出现的数字", "translatedContent": "
表:Logs
\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| id | int |\n| num | varchar |\n+-------------+---------+\n在 SQL 中,id 是该表的主键。\nid 是一个自增列。\n\n
\n\n
找出所有至少连续出现三次的数字。
\n\n返回的结果表中的数据可以按 任意顺序 排列。
\n\n结果格式如下面的例子所示:
\n\n\n\n
示例 1:
\n\n\n输入:\nLogs 表:\n+----+-----+\n| id | num |\n+----+-----+\n| 1 | 1 |\n| 2 | 1 |\n| 3 | 1 |\n| 4 | 2 |\n| 5 | 1 |\n| 6 | 2 |\n| 7 | 2 |\n+----+-----+\n输出:\nResult 表:\n+-----------------+\n| ConsecutiveNums |\n+-----------------+\n| 1 |\n+-----------------+\n解释:1 是唯一连续出现至少三次的数字。\n", "isPaidOnly": false, "difficulty": "Medium", "likes": 820, "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, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": 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" }, { "lang": "Pandas", "langSlug": "pythondata", "code": "import pandas as pd\n\ndef consecutive_numbers(logs: pd.DataFrame) -> pd.DataFrame:\n ", "__typename": "CodeSnippetNode" }, { "lang": "PostgreSQL", "langSlug": "postgresql", "code": "-- Write your PostgreSQL query statement below", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"169.2K\", \"totalSubmission\": \"358.1K\", \"totalAcceptedRaw\": 169206, \"totalSubmissionRaw\": 358056, \"acRate\": \"47.3%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "{\"headers\": {\"Logs\": [\"id\", \"num\"]}, \"rows\": {\"Logs\": [[1, 1], [2, 1], [3, 1], [4, 2], [5, 1], [6, 2], [7, 2]]}}", "metaData": "{\"mysql\":[\"Create table If Not Exists Logs (id int, num int)\"],\"mssql\":[\"Create table Logs (id int, num int)\"],\"oraclesql\":[\"Create table Logs (id int, num int)\"],\"database\":true,\"name\":\"consecutive_numbers\",\"pythondata\":[\"Logs = pd.DataFrame([], columns=['id', 'num']).astype({'id':'Int64', 'num':'Int64'})\"],\"postgresql\":[\"Create table If Not Exists Logs (id int, num int)\"],\"database_schema\":{\"Logs\":{\"id\":\"INT\",\"num\":\"INT\"}}}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists Logs (id int, num int)", "Truncate table Logs", "insert into Logs (id, num) values ('1', '1')", "insert into Logs (id, num) values ('2', '1')", "insert into Logs (id, num) values ('3', '1')", "insert into Logs (id, num) values ('4', '2')", "insert into Logs (id, num) values ('5', '1')", "insert into Logs (id, num) values ('6', '2')", "insert into Logs (id, num) values ('7', '2')" ], "enableRunCode": true, "envInfo": "{\"mysql\":[\"MySQL\",\"
\\u7248\\u672c\\uff1a mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\" Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\" Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\" PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\": {\"Logs\": [\"id\", \"num\"]}, \"rows\": {\"Logs\": [[1, 1], [2, 1], [3, 1], [4, 2], [5, 1], [6, 2], [7, 2]]}}",
"__typename": "QuestionNode"
}
}
}MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"