fix(defaulter_filter): recovery subquery
gitea/salix/pipeline/pr-master This commit looks good Details

This commit is contained in:
Alex Moreno 2024-08-12 10:27:26 +02:00
parent 38dbe6e966
commit 46abf2f57b
1 changed files with 8 additions and 3 deletions

View File

@ -83,9 +83,14 @@ module.exports = Self => {
LEFT JOIN account.user u ON u.id = c.salesPersonFk
LEFT JOIN account.user uw ON uw.id = co.workerFk
LEFT JOIN (
SELECT MAX(started), clientFk, finished
FROM recovery
GROUP BY clientFk
SELECT r1.started, r1.clientFk, r1.finished
FROM recovery r1
JOIN (
SELECT MAX(started) AS maxStarted, clientFk
FROM recovery
GROUP BY clientFk
) r2 ON r1.clientFk = r2.clientFk
AND r1.started = r2.maxStarted
) r ON r.clientFk = c.id
LEFT JOIN workerDepartment wd ON wd.workerFk = u.id
JOIN department dp ON dp.id = wd.departmentFk