-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1164.sql
More file actions
38 lines (35 loc) · 883 Bytes
/
1164.sql
File metadata and controls
38 lines (35 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
with
product_change_price_after as (
select
product_id,
10 as price
from Products
group by product_id
having(min(change_date) > "20190816")
),
id_last_date_before as (
select
product_id,
max(change_date) as last_date
from
Products
where change_date <= "20190816"
group by product_id
),
prodcut_change_price_before as (
select distinct
p.product_id,
new_price as price
from
Products p
inner join id_last_date_before d
on (p.product_id = d.product_id and p.change_date = d.last_date)
)
select
product_id,
price
from (
select * from product_change_price_after
union
select * from prodcut_change_price_before
) as result