1SELECT
2 cat_name,
3 max_pet_date
4FROM cat_dim
5LEFT JOIN (
6 SELECT
7 cat_id,
8 MAX(timestamp)::DATE AS max_pet_date,
9 MIN(timestamp)::DATE AS min_pet_date
10 FROM cat_pet_fact
11 GROUP BY cat_id
12) AS avg_pet_count_over_time
13ON cat_dim.cat_id = avg_pet_count_over_time.cat_id;
14