Untitled

From Morose Teal, 2 Months ago, written in SQL, viewed 56 times.
URL http://codebin.org/view/f031133a Embed
Download Paste or View Raw
  1. WITH temp_event AS
  2. (
  3.     SELECT CAST(DATE_TRUNC('MONTH', event_time) AS DATE) AS MONTH,
  4.        COUNT(*) AS event_count
  5. FROM tools_shop.events AS te
  6. JOIN tools_shop.users AS tu ON te.user_id = tu.user_id
  7. JOIN tools_shop.orders AS o ON tu.user_id = o.user_id
  8.  
  9. WHERE event_name = 'view_item'
  10. GROUP BY MONTH HAVING COUNT(o.order_id) >= 1
  11. )
  12.  
  13. SELECT MONTH,
  14.        event_count,
  15.        SUM(event_count) OVER (ORDER BY MONTH)
  16. FROM temp_event

Reply to "Untitled"

Here you can reply to the paste above