From Little Peccary, 2 Months ago, written in Plain Text, viewed 49 times.
URL http://codebin.org/view/1268fd9d Embed
Download Paste or View Raw
  1. with
  2. profiles as (select user_id, date_trunc('month', created_at)::date as chogort_st,
  3.         count(*) over (partition by date_trunc('month', created_at))
  4. from tools_shop.users)
  6. select EXTRACT(month FROM AGE(DATE_TRUNC('month', o.paid_at), p.chogort_st)) AS lifetime,
  7.         DATE_TRUNC('month', o.paid_at)::date AS order_date,
  8.         p.chogort_st,
  9.         p.count, o.total_amt
  10. from profiles p
  11. join tools_shop.orders o on o.user_id=p.user_id

Reply to "Untitled"

Here you can reply to the paste above