В настоящее время я работаю в проекте express.js и использую knex для переноса базы данных и запросов. У меня проблемы с написанием запросов, чтобы получить точный результат, полученный в postgresql (dbeaver).Ниже приведен запрос, который мне нужно преобразовать в запрос knex (из таблицы). На самом деле хочет получить количество столбцов на основе различных значений столбца (приложений)
select count(job_id) as total_applicants ,
(select count(job_id) from applications as APPL join
recruiter_positions as POS on POS.position_id=APPL.job_id
where APPL.state='qualified' and POS.creator_id='e5f604be-e773-490b-
a525-fad3b95fd941') as qlCount,
(select count(job_id) from applications as APPL join
recruiter_positions as POS on POS.position_id=APPL.job_id
where APPL.state='backup' and POS.creator_id='e5f604be-e773-490b-a525-
fad3b95fd941') as bckCount,
(select count(job_id) from applications as APPL join
recruiter_positions as POS on POS.position_id=APPL.job_id
where APPL.state='interview' and POS.creator_id='e5f604be-e773-490b-
a525-fad3b95fd941') as intrCount,
(select count(job_id) from applications as APPL join
recruiter_positions as POS on POS.position_id=APPL.job_id
where APPL.state='offer' and POS.creator_id='e5f604be-e773-490b-a525-
fad3b95fd941') as offrCount,
(select count(job_id) from applications as APPL join
recruiter_positions as POS on POS.position_id=APPL.job_id
where APPL.state='screening' and POS.creator_id='e5f604be-e773-490b-
a525-fad3b95fd941') as screenCount,
(select count(job_id) from applications as APPL join
recruiter_positions as POS on POS.position_id=APPL.job_id
where APPL.state='rejected' and POS.creator_id='e5f604be-e773-490b-
a525-fad3b95fd941') as rejectedCount
from applications as APPL join recruiter_positions as POS on
POS.position_id=APPL.job_id
where APPL.state notnull and POS.creator_id='e5f604be-e773-490b-a525-
fad3b95fd941'