tak's data blog

LeetCode 문제풀이 (1795) 본문

SQL

LeetCode 문제풀이 (1795)

hyuntaek 2022. 7. 4. 23:19
반응형
SMALL

 

 

#1795

select * from
(select product_id, 'store1' as store, store1 as price from Products
union
select product_id, 'store2' as store, store2 as price from Products
union
select product_id, 'store3' as store, store3 as price from Products) t
where price is not null

store1, store2, store3 각각의 칼럼을 전체적인 store과 price로 피벗테이블로 만드는 것과 동일한 문제이다.

각각의 store칼럼별로 새롭게 테이블을 만든 후 union으로 결합해 해결할 수 있다.

 

 

여기까지 무료로 제공되는 리트코드의 예제들을 풀어보았다. 블로그에 기록하지 않은 문제들도 있다. 추후에 다시 복습을 하면서 풀어볼 때 조금이라도 헷갈리거나 풀리지 않는다면 게시물을 수정하며 다시 문제를 올리도록 하겠다.

반응형
LIST

'SQL' 카테고리의 다른 글

리트코드 SQL 50  (0) 2024.04.09
LeetCode 문제풀이 (1393, 1407, 1484, 1581)  (1) 2022.07.01
LeetCode 문제풀이 (626, 1158)  (0) 2022.06.27
LeetCode 문제풀이 (262)  (0) 2022.06.26
LeetCode 문제풀이 (184, 185)  (0) 2022.06.26