Advertisement
pmkhlv

Untitled

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