Author: Not specified Language: sql
Description: Not specified Timestamp: 2018-01-13 15:51:43 +0000
View raw paste Reply
  1.  
  2. WITH total_rides AS(
  3.  
  4.   WITH actives AS (
  5.     SELECT * FROM riders WHERE account_created_datetime>='2016-01-01 00:00:00' AND
  6.      account_created_datetime<='2017-01-01 00:00:00' AND active=TRUE)
  7.   SELECT actives.rider_id, rides.ride_datetime::date, count(rides.ride_id) FROM actives JOIN rides ON
  8.   actives.rider_id = rides.rider_id WHERE rides.is_complete=true GROUP BY actives.rider_id,
  9.   rides.ride_datetime::date)
  10.  
  11. SELECT rider_id AS "Rider ID", to_char(avg(count),'FM999999999.00') AS "Average Daily Rides (on days when rides are taken)"
  12.  FROM total_rides GROUP BY rider_id;
  13.  
View raw paste Reply