Skip to content

Commit 56a7f59

Browse files
authored
Update 34-01164-product-price-at-a-given-date.sql
1 parent 4fc6ed1 commit 56a7f59

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

34-01164-product-price-at-a-given-date.sql

+21
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ from Products
2222
group by 1
2323
having min(change_date) > '2019-08-16'
2424

25+
--------------------------------------------------------------------------------------------------------------------------------
26+
27+
-- same but without using rank
28+
29+
select product_id, new_price as price
30+
from Products
31+
where (product_id, change_date) in
32+
(
33+
select product_id, max(change_date) as change_date
34+
from Products
35+
where change_date <= '2019-08-16'
36+
group by product_id
37+
)
38+
39+
union
40+
41+
select product_id, 10 as price
42+
from Products
43+
group by 1
44+
having min(change_date) > '2019-08-16'
45+
2546

2647
-- google- 2
2748
-- amazon- 4

0 commit comments

Comments
 (0)