Find Products with Valid Serial Numbers
<p>Table: <code>products</code></p>

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

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

<ul>
	<li>It starts with the letters <strong>SN</strong>&nbsp;(case-sensitive).</li>
	<li>Followed by exactly <code>4</code> digits.</li>
	<li>It must have a hyphen (-) <strong>followed by exactly</strong> <code>4</code> digits.</li>
	<li>The serial number must be within the description (it may not necessarily start at the beginning).</li>
</ul>

<p>Return <em>the result table&nbsp;ordered by</em> <code>product_id</code> <em>in <strong>ascending</strong> order</em>.</p>

<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example:</strong></p>

<div class="example-block">
<p><strong>Input:</strong></p>

<p>products table:</p>

<pre class="example-io">
+------------+--------------+------------------------------------------------------+
| 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            |
+------------+--------------+------------------------------------------------------+
    </pre>

<p><strong>Output:</strong></p>

<pre class="example-io">
+------------+--------------+------------------------------------------------------+
| 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            |
+------------+--------------+------------------------------------------------------+
    </pre>

<p><strong>Explanation:</strong></p>

<ul>
	<li><strong>Product 1:</strong> Valid serial number SN1234-5678</li>
	<li><strong>Product 2:</strong> Valid serial number SN9876-1234</li>
	<li><strong>Product 3:</strong> Invalid serial number SN1234-56789 (contains 5 digits after the hyphen)</li>
	<li><strong>Product 4:</strong> No serial number in the description</li>
	<li><strong>Product 5:</strong> Valid serial number SN4321-8765</li>
</ul>

<p>The result table is ordered by product_id in ascending order.</p>
</div>

[]
['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')"]
[{"value": "mysql", "text": "MySQL", "defaultCode": "# Write your MySQL query statement below\n"}, {"value": "mssql", "text": "MS SQL Server", "defaultCode": "/* Write your T-SQL query statement below */\n"}, {"value": "oraclesql", "text": "Oracle", "defaultCode": "/* Write your PL/SQL query statement below */\n"}, {"value": "pythondata", "text": "Pandas", "defaultCode": "import pandas as pd\n\ndef find_valid_serial_products(products: pd.DataFrame) -> pd.DataFrame:\n    "}, {"value": "postgresql", "text": "PostgreSQL", "defaultCode": "-- Write your PostgreSQL query statement below\n"}]
{"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)"}}}
{"mysql": ["MySQL", "<p><code>MySQL 8.0</code>.</p>"], "mssql": ["MS SQL Server", "<p><code>mssql server 2019</code>.</p>"], "oraclesql": ["Oracle", "<p><code>Oracle Sql 11.2</code>.</p>"], "pythondata": ["Pandas", "<p>Python 3.10 with Pandas 2.2.2 and NumPy 1.26.4</p>"], "postgresql": ["PostgreSQL", "<p>PostgreSQL 16</p>"]}
['Database']