https://leetcode.com/problems/rearrange-products-table
Rearrange Products Table - LeetCode
Can you solve this real interview question? Rearrange Products Table - Table: Products +-------------+---------+ | Column Name | Type | +-------------+---------+ | product_id | int | | store1 | int | | store2 | int | | store3 | int | +-------------+-------
leetcode.com
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
UNION을 이용해서 각 store의 행을 합친 결과를 추출했다.
'코딩테스트 > SQL' 카테고리의 다른 글
[LeetCode][MySQL] Tree Node (0) | 2024.01.03 |
---|---|
[LeetCode][MySQL] Friend Requests II: Who Has the Most Friends (1) | 2024.01.03 |
[LeetCode][MySQL] Group Sold Products By The Date (0) | 2023.12.20 |
[LeetCode][MySQL] Triangle Judgement (0) | 2023.12.13 |
[LeetCode][MySQL] Sales Person (0) | 2023.12.13 |