instruction: Question age distribution and average views.
response: WITH post_age_and_views AS (SELECT Id, CAST(ViewCount AS FLOAT) AS viewcount, CAST((JULIANDAY(CURRENT_TIMESTAMP()) - JULIANDAY(CreationDate)) * 1440.0 AS INT) / 1440.0 AS age_in_days FROM Posts WHERE PostTypeId = 1), stats AS (SELECT CAST(MAX(age_in_days) AS FLOAT) AS max_age, CAST(COUNT(1) AS FLOAT) AS num_posts, CAST(MAX(ViewCount) AS FLOAT) AS max_views FROM post_age_and_views), binned AS (SELECT CEIL((age_in_days / s.max_age) / 0.05) AS bin, ViewCount FROM post_age_and_views JOIN stats AS s ON 1 = 1) SELECT bin, AVG(ViewCount) / MAX(max_views) AS "average_view_count_(%_of_max)", COUNT(*) / MAX(num_posts) AS "posts_in_bin_(%_of_total)" FROM binned JOIN stats ON 1 = 1 GROUP BY bin ORDER BY bin