File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ Have a good contributing!
8888 - [ 1045. Customers Who Bought All Products] ( ./leetcode/medium/1045.%20Customers%20Who%20Bought%20All%20Products.sql )
8989 - [ 1070. Product Sales Analysis III] ( ./leetcode/medium/1070.%20Product%20Sales%20Analysis%203.sql )
9090 - [ 1158. Market Analysis 1] ( ./leetcode/medium/1158.%20Market%20Analysis%201.sql )
91+ - [ 1164. Product Price at a Given Date] ( ./leetcode/medium/1164.%20Product%20Price%20at%20a%20Given%20Date.sql )
9192 - [ 1174. Immediate Food Delivery II] ( ./leetcode/medium/1174.%20Immediate%20Food%20Delivery%20II.sql )
9293 - [ 1193. Monthly Transactions I] ( ./leetcode/medium/1193.%20Monthly%20Transactions%20I.sql )
9394 - [ 1204. Last Person to Fit in the Bus] ( ./leetcode/medium/1204.%20Last%20Person%20to%20Fit%20in%20the%20Bus.sql )
Original file line number Diff line number Diff line change 1+ /*
2+ Question 1164. Product Price at a Given Date
3+ Link: https://leetcode.com/problems/product-price-at-a-given-date/description/?envType=study-plan-v2&envId=top-sql-50
4+
5+ Table: Products
6+
7+ +---------------+---------+
8+ | Column Name | Type |
9+ +---------------+---------+
10+ | product_id | int |
11+ | new_price | int |
12+ | change_date | date |
13+ +---------------+---------+
14+ (product_id, change_date) is the primary key (combination of columns with unique values) of this table.
15+ Each row of this table indicates that the price of some product was changed to a new price at some date.
16+ Initially, all products have price 10.
17+
18+ Write a solution to find the prices of all products on the date 2019-08-16.
19+
20+ Return the result table in any order.
21+ */
22+
23+ SELECT DISTINCT
24+ p .product_id ,
25+ COALESCE(
26+ (
27+ SELECT p1 .new_price
28+ FROM Products AS p1
29+ WHERE
30+ p1 .change_date <= ' 2019-08-16'
31+ AND p1 .product_id = p .product_id
32+ ORDER BY p1 .change_date DESC
33+ LIMIT 1
34+ ), 10
35+ ) AS price
36+ FROM Products AS p
You can’t perform that action at this time.
0 commit comments