Untitled

From Obese Ostrich, 4 Months ago, written in Plain Text, viewed 60 times.
URL http://codebin.org/view/82942871 Embed
Download Paste or View Raw
  1. SELECT DISTINCT
  2.         user_id,
  3.         CAST(DATE_TRUNC('month', paid_at ) as date) AS month_nbr,
  4.         MIN(CAST(DATE_TRUNC('month', paid_at ) as date)) OVER(PARTITION BY user_id) as cohort
  5. FROM tools_shop.orders
  6. ORDER BY user_id, month_nbr

Reply to "Untitled"

Here you can reply to the paste above