Calculate difference between SUM over last 30 days and the SUM for 30 days preceding this period (days 30-60) in Postgres
Especially the CTEs might be a problem. So it needs to be rewritten anyway. And while at it, I'd rewrite this to use conditional aggregation. That should get the data in "one run", without two temporary results and a join on them.

SELECT metric_data.company_id,
       sum(CASE
             WHEN metric_data.recorded_at &gt; current_date - INTERVAL '30 day' THEN
               1
             ELSE
               0
           END) current_jobs_posted,
       sum(CASE
             WHEN metric_data.recorded_at &gt; current_date - INTERVAL '30 day' THEN
               1
             ELSE
               -1
           END) delta
       FROM metric_data
       WHERE metric_data.recorded_at &gt;= current_date - INTERVAL '60 day'
       GROUP BY metric_data.company_id;


(You might want to check the comparison operators (&gt;=, &gt;, etc.), if I picked the ones you wanted.)

An index on recorded_at and company_id should support it.

CREATE INDEX metric_data_recorded_at_company_id
             ON metric_data(recorded_at,
                            company_id);


Like that the entire query should be answerable from the index alone, without using the table at all. But maybe you also want to try it with an index just on recorded_at alone.