Skip to content

Commit 473b566

Browse files
authored
Create rearrange-products-table.sql
1 parent 5b99417 commit 473b566

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

MySQL/rearrange-products-table.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
SELECT product_id,
5+
'store1' AS store,
6+
store1 AS price
7+
FROM products
8+
WHERE store1 IS NOT NULL
9+
UNION ALL
10+
SELECT product_id,
11+
'store2' AS store,
12+
store2 AS price
13+
FROM products
14+
WHERE store2 IS NOT NULL
15+
UNION ALL
16+
SELECT product_id,
17+
'store3' AS store,
18+
store3 AS price
19+
FROM products
20+
WHERE store3 IS NOT NULL;

0 commit comments

Comments
 (0)