SQL/LeetCode

[LeetCode] 1795. Rearrange Products Table

yeyeyep 2025. 2. 21. 15:49

 

 

[문제]

이미지를 누르면 문제 링크로 넘어갑니다

 

 

[MySQL]

SELECT product_id
     , 'store1' AS store
     , store1 AS price
FROM Products
WHERE store1 IS NOT NULL

UNION ALL

SELECT product_id
     , 'store2' AS store
     , store2 AS price
FROM Products
WHERE store2 IS NOT NULL

UNION ALL

SELECT product_id
     , 'store3' AS store
     , store3 AS price
FROM Products
WHERE store3 IS NOT NULL