表:products
+--------------+------------+ | Column Name | Type | +--------------+------------+ | product_id | int | | product_name | varchar | | description | varchar | +--------------+------------+ (product_id) 是这张表的唯一主键。 这张表的每一行表示一个产品的唯一 ID,名字和描述。
编写一个解决方案来找到所有描述中 包含一个有效序列号 模式的产品。一个有效序列号符合下述规则:
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 | +------------+--------------+------------------------------------------------------+
解释:
结果表以 product_id 升序排序。