{ "data": { "question": { "questionId": "3792", "questionFrontendId": "3451", "categoryTitle": "Database", "boundTopicId": 3073058, "title": "Find Invalid IP Addresses", "titleSlug": "find-invalid-ip-addresses", "content": "
Table: logs
\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| log_id | int |\n| ip | varchar |\n| status_code | int |\n+-------------+---------+\nlog_id is the unique key for this table.\nEach row contains server access log information including IP address and HTTP status code.\n\n\n
Write a solution to find invalid IP addresses. An IPv4 address is invalid if it meets any of these conditions:
\n\n255
in any octet01.02.03.04
)4
octetsReturn the result table ordered by invalid_count
, ip
in descending order respectively.
The result format is in the following example.
\n\n\n
Example:
\n\nInput:
\n\nlogs table:
\n\n\n+--------+---------------+-------------+\n| log_id | ip | status_code | \n+--------+---------------+-------------+\n| 1 | 192.168.1.1 | 200 | \n| 2 | 256.1.2.3 | 404 | \n| 3 | 192.168.001.1 | 200 | \n| 4 | 192.168.1.1 | 200 | \n| 5 | 192.168.1 | 500 | \n| 6 | 256.1.2.3 | 404 | \n| 7 | 192.168.001.1 | 200 | \n+--------+---------------+-------------+\n\n\n
Output:
\n\n\n+---------------+--------------+\n| ip | invalid_count|\n+---------------+--------------+\n| 256.1.2.3 | 2 |\n| 192.168.001.1 | 2 |\n| 192.168.1 | 1 |\n+---------------+--------------+\n\n\n
Explanation:
\n\nThe output table is ordered by invalid_count, ip in descending order respectively.
\n表:logs
\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| log_id | int |\n| ip | varchar |\n| status_code | int |\n+-------------+---------+\nlog_id 是这张表的唯一主键。\n每一行包含服务器访问日志信息,包括 IP 地址和 HTTP 状态码。\n\n\n
编写一个解决方案来查找 无效的 IP 地址。一个 IPv4 地址如果满足以下任何条件之一,则无效:
\n\n01.02.03.04
)4
个 8 位字节返回结果表分别以 invalid_count
,ip
降序 排序。
结果格式如下所示。
\n\n\n\n
示例:
\n\n输入:
\n\nlogs 表:
\n\n\n+--------+---------------+-------------+\n| log_id | ip | status_code | \n+--------+---------------+-------------+\n| 1 | 192.168.1.1 | 200 | \n| 2 | 256.1.2.3 | 404 | \n| 3 | 192.168.001.1 | 200 | \n| 4 | 192.168.1.1 | 200 | \n| 5 | 192.168.1 | 500 | \n| 6 | 256.1.2.3 | 404 | \n| 7 | 192.168.001.1 | 200 | \n+--------+---------------+-------------+\n\n\n
输出:
\n\n\n+---------------+--------------+\n| ip | invalid_count|\n+---------------+--------------+\n| 256.1.2.3 | 2 |\n| 192.168.001.1 | 2 |\n| 192.168.1 | 1 |\n+---------------+--------------+\n\n\n
解释:
\n\n输出表分别以 invalid_count
,ip
降序排序。
\\u7248\\u672c\\uff1a mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\" Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\" Python 3.10 with Pandas 2.2.2 and NumPy 1.26.4<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\" PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"logs\":[\"log_id\",\"ip\",\"status_code\"]},\"rows\":{\"logs\":[[1,\"192.168.1.1\",200],[2,\"256.1.2.3\",404],[3,\"192.168.001.1\",200],[4,\"192.168.1.1\",200],[5,\"192.168.1\",500],[6,\"256.1.2.3\",404],[7,\"192.168.001.1\",200]]}}",
"__typename": "QuestionNode"
}
}
}MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"