AS users_count FROM visits WHERE visits.created_at > '2019-09-25 21:46:35 +0300'"::timestamp AND visits.created_at < '2019-09-25 23:46:35 +0300'"::timestamp GROUP BY 1 !15
DATE_TRUNC('minute', now()) - '6 hours'"::interval, DATE_TRUNC('minute', now()), '1 minute'"::interval ) as minute ) SELECT minutes.minute AS time, COUNT(DISTINCT(visits.user_id)) AS users_count FROM minutes LEFT JOIN users ON DATE_TRUNC('minute', visits.created_at) = minutes.minute GROUP BY 1 !17
"-- of course if we have window functions SELECT price - lag(price) OVER my_window FROM stock_prices WINDOW my_window AS (ORDER BY created_at ASC) WHERE series_id = 'some' !21
sum(time_spent) AS total_spent, count(distinct(user_id)) AS user_count, count(distinct(account_id)) AS account_count INTO course_visits_by_day FROM visits GROUP BY time(1d), course_id END !40
result for 1 minute # some magic VisitMetrics.where(course_session_id: 100500).past(:hour) # fetch from cache course_session.visits # performing and caching with default expiring time !50