调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
简单
相关标签
相关企业
SQL Schema
Pandas Schema

表:products

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

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

  • SN 字母开头(区分大小写)。
  • 后面有恰好 4 位数字。
  • 接着是一个短横(-), 短横后面还有另一组 4 位数字
  • 序列号必须在描述内(可能不在描述的开头)

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

结果格式如下所示。

 

示例:

输入:

products 表:

+------------+--------------+------------------------------------------------------+
| product_id | product_name | description                                          |
+------------+--------------+------------------------------------------------------+
| 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            |
+------------+--------------+------------------------------------------------------+
    

输出:

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

解释:

  • 产品 1:有效的序列号 SN1234-5678
  • 产品 2:有效的序列号 SN9876-1234
  • 产品 3:无效的序列号 SN1234-56789(短横后包含 5 位数字)
  • 产品 4:描述中没有序列号
  • 产品 5:有效的序列号 SN4321-8765

结果表以 product_id 升序排序。

通过次数
688
提交次数
849
通过率
81.0%

相关标签

相关企业

评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
运行和提交代码需要登录
products =
| product_id | product_name | description | | ---------- | ------------ | ---------------------------------------------------- | | 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 |