bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1164. Product Price at a Given Date

1164. Product Price at a Given Date

Leetcode Solutions

Approach: Divide cases by using UNION ALL

  1. Select all product_id values where the minimum change_date is greater than 2019-08-16 and assign a price of 10 to them.
  2. For each product_id, find the maximum change_date that is less than or equal to 2019-08-16.
  3. Join the result of step 2 with the original Products table to get the new_price for the last change date.
  4. Use UNION ALL to combine the results of step 1 and step 3 into a single result set.
erDiagram
    Products {
        int product_id
        int new_price
        date change_date
    }

Approach: Divide cases by using LEFT JOIN

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...