Advertisement
pmkhlv

Untitled

May 26th, 2022
555
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select
  2.     user_id,
  3.     max(order_ts) over (partition by user_id) as last_order_date, -- дата последнего заказа
  4.     count(*) over (partition by user_id) as sum_orders, -- количество заказов у каждого клиента
  5.     sum(payment) over (partition by user_id) as sum_payment -- сумма заказов по клиенту
  6.   from
  7.     analysis.users_v u left join analysis.orders_v o on u.id = o.user_id
  8.   where
  9.     order_ts > '2021-01-01' and status = 4
Advertisement
RAW Paste Data Copied
Advertisement