1948. Rearrange Products Table
My accepted SQL solution to LeetCode problem 1948, Rearrange Products Table, running in 478ms.
- Difficulty: Easy
- SQL
- Runtime 478ms
- Memory 0.0B
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
SQL
Accepted on LeetCode — runtime 478ms, memory 0.0B, accepted 2025-12-31.
SELECT product_id, 'store1' AS store, store1 AS price FROM Products WHERE store1 IS NOT NULL
UNION
SELECT product_id, 'store2' AS store, store2 AS price FROM Products WHERE store2 IS NOT NULL
UNION
SELECT product_id, 'store3' AS store, store3 AS price FROM Products WHERE store3 IS NOT NULL