문제
입력 코드
SELECT
DISTINCT product_id,
10 AS price
FROM Products
WHERE product_id NOT IN (SELECT DISTINCT product_id
FROM Products
WHERE change_date <= '2019-08-16' )
UNION
SELECT
product_id,
new_price AS price
FROM Products
WHERE (product_id,change_date) IN (SELECT product_id ,
MAX(change_date) AS date
FROM Products
WHERE change_date <= '2019-08-16'
GROUP BY product_id)
코드 설명
#SELECT #DISTINCT #NOT IN #UNION #MAX #GROUP BY
문제 출처
'SQL' 카테고리의 다른 글
#110. [LeetCode / MySQL] 1907. Count Salary Categories (0) | 2023.10.06 |
---|---|
#109. [LeetCode / MySQL] 1204. Last Person to Fit in the Bus (0) | 2023.10.05 |
#107. [LeetCode / MySQL] 180. Consecutive Numbers (0) | 2023.10.03 |
#106. [LeetCode / MySQL] 610. Triangle Judgement (0) | 2023.10.02 |
#105. [LeetCode / MySQL] 1789. Primary Department for Each Employee (0) | 2023.10.01 |