stats.sql 875 B

123456789101112131415
  1. -- Contests by month
  2. SELECT strftime('%Y-%m', datetime(start_time / 1000, 'unixepoch')) as month, COUNT(*) as nb_contests FROM game GROUP BY strftime('%Y-%m', datetime(start_time / 1000, 'unixepoch'));
  3. -- Scores by month
  4. SELECT strftime('%Y-%m', datetime(created_at / 1000, 'unixepoch')) as month, COUNT(*) as nb_scores FROM score GROUP BY strftime('%Y-%m', datetime(created_at / 1000, 'unixepoch'));
  5. -- New users per month (only counting users with >5 games)
  6. select strftime('%Y-%m', datetime(created_at / 1000, 'unixepoch')), COUNT(*) as new_users
  7. from score as t1, user
  8. inner join rating on user.user_id = rating.user_id
  9. where total_scores > 5 and t1.user_id = user.user_id
  10. and not exists(
  11. select 1 from score as t2 where t1.created_at / 1000 < t2.created_at / 1000 AND t1.user_id = t2.user_id
  12. )
  13. GROUP BY strftime('%Y-%m', datetime(created_at / 1000, 'unixepoch'));