generated from yandex-praktikum/de-project-sprint-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d065a6
commit 7daf181
Showing
1 changed file
with
13 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
create or replace view analysis.orders as | ||
select | ||
o.order_id, | ||
o.order_ts, | ||
o.user_id, | ||
o.bonus_payment, | ||
o.payment, | ||
o.cost, | ||
select o.order_id, | ||
osl.dttm as "order_ts", | ||
o.user_id, | ||
o.bonus_payment, | ||
o.payment, | ||
o."cost", | ||
o.bonus_grant, | ||
osl.status_id "status" | ||
from | ||
production.orders o | ||
inner join | ||
production.orderstatuslog osl | ||
on 1 = 1 | ||
and o.order_id = osl.order_id | ||
and o.order_ts = osl.dttm | ||
where osl.dttm >= '2022-01-01'; | ||
osl.status_id as "status" | ||
from production.orders o | ||
left join production.orderstatuslog osl | ||
on osl.order_id = o.order_id | ||
and osl.dttm = (select max(osl2.dttm) | ||
from production.orderstatuslog osl2 | ||
where osl2.order_id = o.order_id); |