{ "data": { "question": { "questionId": "3803", "questionFrontendId": "3465", "categoryTitle": "Database", "boundTopicId": 3087164, "title": "Find Products with Valid Serial Numbers", "titleSlug": "find-products-with-valid-serial-numbers", "content": "

Table: products

\n\n
\n+--------------+------------+\n| Column Name  | Type       |\n+--------------+------------+\n| product_id   | int        |\n| product_name | varchar    |\n| description  | varchar    |\n+--------------+------------+\n(product_id) is the unique key for this table.\nEach row in the table represents a product with its unique ID, name, and description.\n
\n\n

Write a solution to find all products whose description contains a valid serial number pattern. A valid serial number follows these rules:

\n\n\n\n

Return the result table ordered by product_id in ascending order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example:

\n\n
\n

Input:

\n\n

products table:

\n\n
\n+------------+--------------+------------------------------------------------------+\n| product_id | product_name | description                                          |\n+------------+--------------+------------------------------------------------------+\n| 1          | Widget A     | This is a sample product with SN1234-5678            |\n| 2          | Widget B     | A product with serial SN9876-1234 in the description |\n| 3          | Widget C     | Product SN1234-56789 is available now                |\n| 4          | Widget D     | No serial number here                                |\n| 5          | Widget E     | Check out SN4321-8765 in this description            |\n+------------+--------------+------------------------------------------------------+\n    
\n\n

Output:

\n\n
\n+------------+--------------+------------------------------------------------------+\n| product_id | product_name | description                                          |\n+------------+--------------+------------------------------------------------------+\n| 1          | Widget A     | This is a sample product with SN1234-5678            |\n| 2          | Widget B     | A product with serial SN9876-1234 in the description |\n| 5          | Widget E     | Check out SN4321-8765 in this description            |\n+------------+--------------+------------------------------------------------------+\n    
\n\n

Explanation:

\n\n\n\n

The result table is ordered by product_id in ascending order.

\n
\n", "translatedTitle": "查找具有有效序列号的产品", "translatedContent": "

表:products

\n\n
\n+--------------+------------+\n| Column Name  | Type       |\n+--------------+------------+\n| product_id   | int        |\n| product_name | varchar    |\n| description  | varchar    |\n+--------------+------------+\n(product_id) 是这张表的唯一主键。\n这张表的每一行表示一个产品的唯一 ID,名字和描述。\n
\n\n

编写一个解决方案来找到所有描述中 包含一个有效序列号 模式的产品。一个有效序列号符合下述规则:

\n\n\n\n

返回结果表以 product_id 升序 排序。

\n\n

结果格式如下所示。

\n\n

 

\n\n

示例:

\n\n
\n

输入:

\n\n

products 表:

\n\n
\n+------------+--------------+------------------------------------------------------+\n| product_id | product_name | description                                          |\n+------------+--------------+------------------------------------------------------+\n| 1          | Widget A     | This is a sample product with SN1234-5678            |\n| 2          | Widget B     | A product with serial SN9876-1234 in the description |\n| 3          | Widget C     | Product SN1234-56789 is available now                |\n| 4          | Widget D     | No serial number here                                |\n| 5          | Widget E     | Check out SN4321-8765 in this description            |\n+------------+--------------+------------------------------------------------------+\n    
\n\n

输出:

\n\n
\n+------------+--------------+------------------------------------------------------+\n| product_id | product_name | description                                          |\n+------------+--------------+------------------------------------------------------+\n| 1          | Widget A     | This is a sample product with SN1234-5678            |\n| 2          | Widget B     | A product with serial SN9876-1234 in the description |\n| 5          | Widget E     | Check out SN4321-8765 in this description            |\n+------------+--------------+------------------------------------------------------+\n    
\n\n

解释:

\n\n\n\n

结果表以 product_id 升序排序。

\n
\n", "isPaidOnly": false, "difficulty": "Easy", "likes": 1, "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, \"cangjie\": 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 find_valid_serial_products(products: pd.DataFrame) -> pd.DataFrame:\n ", "__typename": "CodeSnippetNode" }, { "lang": "PostgreSQL", "langSlug": "postgresql", "code": "-- Write your PostgreSQL query statement below", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"442\", \"totalSubmission\": \"542\", \"totalAcceptedRaw\": 442, \"totalSubmissionRaw\": 542, \"acRate\": \"81.5%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "{\"headers\":{\"products\":[\"product_id\",\"product_name\",\"description\"]},\"rows\":{\"products\":[[1,\"Widget A\",\"This is a sample product with SN1234-5678\"],[2,\"Widget B\",\"A product with serial SN9876-1234 in the description\"],[3,\"Widget C\",\"Product SN1234-56789 is available now\"],[4,\"Widget D\",\"No serial number here\"],[5,\"Widget E\",\"Check out SN4321-8765 in this description\"]]}}", "metaData": "{\"mysql\":[\"CREATE TABLE If not exists products (\\n product_id INT,\\n product_name VARCHAR(255),\\n description VARCHAR(255)\\n)\\n\"],\"mssql\":[\"CREATE TABLE products (\\n product_id INT,\\n product_name VARCHAR(255),\\n description VARCHAR(255)\\n)\"],\"oraclesql\":[\"CREATE TABLE products (\\n product_id NUMBER,\\n product_name VARCHAR2(255),\\n description VARCHAR2(255)\\n)\\n\"],\"database\":true,\"name\":\"find_valid_serial_products\",\"postgresql\":[\"CREATE TABLE IF NOT EXISTS products (\\n product_id SERIAL PRIMARY KEY,\\n product_name VARCHAR(255) NOT NULL,\\n description TEXT\\n);\\n\"],\"pythondata\":[\"products = pd.DataFrame(columns=['product_id', 'product_name', 'description']).astype({'product_id': 'int32', 'product_name': 'string', 'description': 'string'})\\n\"],\"database_schema\":{\"products\":{\"product_id\":\"INT\",\"product_name\":\"VARCHAR(255)\",\"description\":\"VARCHAR(255)\"}}}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "CREATE TABLE If not exists products (\n product_id INT,\n product_name VARCHAR(255),\n description VARCHAR(255)\n)\n", "Truncate table products", "insert into products (product_id, product_name, description) values ('1', 'Widget A', 'This is a sample product with SN1234-5678')", "insert into products (product_id, product_name, description) values ('2', 'Widget B', 'A product with serial SN9876-1234 in the description')", "insert into products (product_id, product_name, description) values ('3', 'Widget C', 'Product SN1234-56789 is available now')", "insert into products (product_id, product_name, description) values ('4', 'Widget D', 'No serial number here')", "insert into products (product_id, product_name, description) values ('5', 'Widget E', 'Check out SN4321-8765 in this description')" ], "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>\"],\"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\":{\"products\":[\"product_id\",\"product_name\",\"description\"]},\"rows\":{\"products\":[[1,\"Widget A\",\"This is a sample product with SN1234-5678\"],[2,\"Widget B\",\"A product with serial SN9876-1234 in the description\"],[3,\"Widget C\",\"Product SN1234-56789 is available now\"],[4,\"Widget D\",\"No serial number here\"],[5,\"Widget E\",\"Check out SN4321-8765 in this description\"]]}}", "__typename": "QuestionNode" } } }