fix(defaulter_filter): recovery subquery #2849

Merged
alexm merged 1 commits from hotFix_defaulterFilter_recovery into master 2024-08-13 06:55:00 +00:00
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 u ON u.id = c.salesPersonFk
LEFT JOIN account.user uw ON uw.id = co.workerFk LEFT JOIN account.user uw ON uw.id = co.workerFk
LEFT JOIN ( LEFT JOIN (
SELECT MAX(started), clientFk, finished SELECT r1.started, r1.clientFk, r1.finished
FROM recovery FROM recovery r1
GROUP BY clientFk 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 ) r ON r.clientFk = c.id
LEFT JOIN workerDepartment wd ON wd.workerFk = u.id LEFT JOIN workerDepartment wd ON wd.workerFk = u.id
JOIN department dp ON dp.id = wd.departmentFk JOIN department dp ON dp.id = wd.departmentFk