Вы можете получить статус проблемы при помощи выборки с соединением таблиц:
select
problems.*,
case when coalesce(max(status_id), 2) = 2 then 'Not Completed' else 'Completed' end problem_status
from problems
left join tasks on tasks.problem_id = problems.id
group by problems.id, problems.title
order by problems.id;
https://sqlize.online/sql/psql13/6be99ff3d4acabd6d...
Или более динамичным способом:
with problem_status as (
select
problems.*,
max(status_id) status_id
from problems
left join tasks on tasks.problem_id = problems.id
group by problems.id, problems.title
) select problem_status.id, problem_status.title, statuses.title
from problem_status
left join statuses on statuses.id = problem_status.status_id
order by problem_status.id;
https://sqlize.online/sql/psql13/946dfddb1805be86e...