
😎풀이
store1
이 NULL
이 아니라면, store1
점수 출력
store2
이 NULL
이 아니라면, store2
점수 출력
store3
이 NULL
이 아니라면, store3
점수 출력
- 해당 컬럼을 UNION으로 엮어 같이 조회회
SELECT
p1.product_id AS product_id,
'store1' AS store,
p1.store1 AS price
FROM Products AS p1
WHERE p1.store1 IS NOT NULL
UNION
SELECT
p2.product_id AS product_id,
'store2' AS store,
p2.store2 AS p2
FROM Products AS p2
WHERE p2.store2 IS NOT NULL
UNION
SELECT
p3.product_id AS product_id,
'store3' AS store,
p3.store3 AS price
FROM Products AS p3
WHERE p3.store3 IS NOT NULL