Gather values from different related rows with JSONB fields
As per comments, you need a timestamp field and I've added it to your sample data.  Now IMHO you should first unnest your jsonb data. I've used a SUM(CASE for this purpose and it calculates too the minimum timestamp value.

SELECT 
    event.job_id, 
    job.some_field,
    event.payload-&gt;&gt;'type' AS type, 
    SUM(CASE WHEN event.payload-&gt;&gt;'a' IS NOT NULL THEN 1 ELSE 0 END) AS a,
    SUM(CASE WHEN event.payload-&gt;&gt;'b' IS NOT NULL THEN 1 ELSE 0 END) AS b,
    SUM(CASE WHEN event.payload-&gt;&gt;'c' IS NOT NULL THEN 1 ELSE 0 END) AS c,
    SUM(CASE WHEN event.payload-&gt;&gt;'d' IS NOT NULL THEN 1 ELSE 0 END) AS d,
    MIN((event.payload-&gt;&gt;'ts'::text)::timestamp) as min_ts
FROM   
    event
JOIN
    job
    ON event.job_id = job.id
GROUP BY 
    event.job_id, 
    job.some_field,
    event.payload-&gt;&gt;'type'
ORDER BY
    1, 2;


This is the result:



job_id | some_field | type |  a |  b |  c |  d | min_ts             
-----: | :--------- | :--- | -: | -: | -: | -: | :------------------
     1 | val1       | 1    |  1 |  0 |  0 |  0 | 2004-10-19 10:23:54
     1 | val1       | 2    |  0 |  0 |  1 |  0 | 2002-10-19 10:23:54
     2 | val2       | 1    |  2 |  0 |  0 |  0 | 2003-10-19 10:23:54
     3 | val3       | 1    |  2 |  0 |  0 |  0 | 2004-10-19 10:23:54
     3 | val3       | 2    |  0 |  0 |  1 |  0 | 2005-10-19 10:23:54
     3 | val3       | 3    |  0 |  0 |  0 |  1 | 2006-10-19 10:23:54



db&lt;>fiddle here

Starting at this point you can easily filter it by type and get the desired result.