2022/12/20

LeetCode 1795. Rearrange Products Table

問題:輸出不同商店的價格
解法:UNION將SELECT語句合併即可
SELECT product_id, "store1" AS store, store1 AS price
FROM Products
WHERE store1 IS NOT NULL
UNION
SELECT product_id, "store2", store2
FROM Products
WHERE store2 IS NOT NULL
UNION
SELECT product_id, "store3", store3
FROM Products
WHERE store3 IS NOT NULL;