[LeetCode/SQL] 1795. Rearrange Products Table

Sooyeon·2023년 11월 15일
0

문제풀이 

목록 보기
65/95
post-thumbnail

[LeetCode/SQL]


📌 1795. Rearrange Products Table

문제업로드중..업로드중..

풀이

- product_id별 store1,2,3에서 null값을 제외하고,
열 변경
==> UNION 사용 

방법

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

0개의 댓글