File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -153,6 +153,7 @@ Useful for preparing for technical interviews and improving your SQL skills.
153153 - [ 1978. Employees Whose Manager Left the Company] ( ./leetcode/easy/1978.%20Employees%20Whose%20Manager%20Left%20the%20Company.sql )
154154 - [ 2356. Number of Unique Subjects Taught by Each Teacher] ( ./leetcode/easy/2356.%20Number%20of%20Unique%20Subjects%20Taught%20by%20Each%20Teacher.sql )
155155 - [ 3436. Find Valid Emails] ( ./leetcode/easy/3436.%20Find%20Valid%20Emails.sql )
156+ - [ 3465. Find Products with Valid Serial Numbers] ( ./leetcode/easy/3465.%20Find%20Products%20with%20Valid%20Serial%20Numbers.sql )
1561572 . [ Medium] ( ./leetcode/medium/ )
157158 - [ 176. Second Highest Salary] ( ./leetcode/medium/176.%20Second%20Highest%20Salary.sql )
158159 - [ 180. Consecutive Numbers] ( ./leetcode/medium/180.%20Consecutive%20Numbers.sql )
Original file line number Diff line number Diff line change 1+ /*
2+ Question 3465. Find Products with Valid Serial Numbers
3+ Link: https://leetcode.com/problems/find-products-with-valid-serial-numbers/description/?envType=problem-list-v2&envId=database
4+
5+ Table: products
6+
7+ +--------------+------------+
8+ | Column Name | Type |
9+ +--------------+------------+
10+ | product_id | int |
11+ | product_name | varchar |
12+ | description | varchar |
13+ +--------------+------------+
14+ (product_id) is the unique key for this table.
15+ Each row in the table represents a product with its unique ID, name, and description.
16+ Write a solution to find all products whose description contains a valid serial number pattern. A valid serial number follows these rules:
17+
18+ It starts with the letters SN (case-sensitive).
19+ Followed by exactly 4 digits.
20+ It must have a hyphen (-) followed by exactly 4 digits.
21+ The serial number must be within the description (it may not necessarily start at the beginning).
22+ Return the result table ordered by product_id in ascending order.
23+ */
24+
25+ SELECT
26+ product_id,
27+ product_name,
28+ description -- noqa
29+ FROM products
30+ WHERE description ~ ' \y SN[0-9]{4}\- [0-9]{4}\y '
31+ ORDER BY product_id ASC
You can’t perform that action at this time.
0 commit comments