Moves LIMIT clause to subqueries for custom time ranges