Untitled

From Sloppy Ibis, 4 Months ago, written in Plain Text, viewed 51 times.
URL http://codebin.org/view/345a9c7e Embed
Download Paste or View Raw
  1. WITH
  2. first AS
  3.       (SELECT u.user_id,
  4.              CAST(DATE_TRUNC('month', e.event_time) as date) AS first_date
  5.       FROM tools_shop.users u
  6.       JOIN tools_shop.orders o ON u.user_id = o.user_id
  7.       JOIN tools_shop.events e ON u.user_id = e.user_id
  8.       GROUP BY u.user_id, first_date),
  9.      
  10. cohort_users AS
  11.   (SELECT first_date,
  12.           COUNT(DISTINCT user_id) AS num_users
  13.    FROM first
  14.    GROUP BY first_date)
  15.    
  16. SELECT
  17.        first_date,
  18.        num_users
  19. FROM cohort_users

Reply to "Untitled"

Here you can reply to the paste above