Problem with Group by

I have a problem realizing one special kind of query:

I have two Models:
Jobs and JobStatus

Every Job has multiple JobStatus.
Every JobStatus has a name and a date.

I now need in my Job Model a field with the name of the JobStatus with the highest date.

Is that easily possible in ATK4?

I have the query written in SQL:
SELECT Name FROM (SELECT JID, MAX(date) AS created_at FROM JobStatus where JID='00b3f29e-8038-432e-ae58-30b755a58482' GROUP BY JID ) AS latest_orders INNER JOIN JobStatus ON JobStatus.JID = latest_orders.JID AND JobStatus.date = latest_orders.created_at

Hello,

This can be done with the ATK4 reporting extension:

@HPL - You can create any type of sub-select through Expression functionality:

$model->addExpression(
  'latest_order_status', 
  $model->refSQL('JobStatuses')
   ->setOrder('date', 'desc')
   ->setLimit(1)
);

Also this might be relevant: https://agile-data.readthedocs.io/en/develop/joins.html#specifying-complex-on-logic