From 7daf1812e0d2b3a36a677d0855fcad116e9baa8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=96=D1=83=D0=BB=D1=8C=20=D0=9A=D0=B8=D1=80=D0=B8=D0=BB?= =?UTF-8?q?=D0=BB?= <118897479+KirillZhul@users.noreply.github.com> Date: Sun, 28 May 2023 16:09:01 +0300 Subject: [PATCH] Update orders_view.sql --- orders_view.sql | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/orders_view.sql b/orders_view.sql index c368b50..cf64f88 100644 --- a/orders_view.sql +++ b/orders_view.sql @@ -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);