This repository was archived by the owner on Sep 8, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +29
-14
lines changed Expand file tree Collapse file tree 1 file changed +29
-14
lines changed Original file line number Diff line number Diff line change
1
+ /*
1
2
# Time: O(mlogn), m is the number of unique product id, n is the number of changed dates
2
3
# Space: O(m)
4
+ */
5
+
6
+ SELECT
7
+ t1 .product_id AS product_id,
8
+ IF(ISNULL(t2 .price ), 10 , t2 .price ) AS price
9
+ FROM
10
+ (SELECT DISTINCT product_id
11
+ FROM products) AS t1
12
+ LEFT JOIN
13
+ (SELECT
14
+ product_id,
15
+ new_price AS price
16
+ FROM
17
+ products
18
+ WHERE
19
+ (product_id, change_date) IN
20
+ (SELECT
21
+ product_id,
22
+ MAX (change_date)
23
+ FROM
24
+ products
25
+ WHERE
26
+ change_date <= ' 2019-08-16'
27
+ GROUP BY
28
+ product_id)
29
+ ) AS t2
30
+ ON
31
+ t1 .product_id = t2 .product_id ;
3
32
4
- SELECT t1 .product_id AS product_id,
5
- IF(Isnull(t2 .price ), 10 , t2 .price ) AS price
6
- FROM (SELECT DISTINCT product_id
7
- FROM products) AS t1
8
- left join (SELECT product_id,
9
- new_price AS price
10
- FROM products
11
- WHERE ( product_id, change_date ) IN (SELECT product_id,
12
- Max (change_date)
13
- FROM products
14
- WHERE change_date <= ' 2019-08-16'
15
- GROUP BY product_id))
16
- AS t2
17
- ON t1 .product_id = t2 .product_id
You can’t perform that action at this time.
0 commit comments