fix(defaulter_filter): recovery subquery #2849
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue