#108. [LeetCode / MySQL] 1164. Product Price at a Given Date

문제

 

입력 코드

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

 

 

문제 출처

 

LeetCode - The World's Leading Online Programming Learning Platform

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com