Well if he is insisting in doing the SQL version of writing everything inside a lambda without modularizing the code, then yeah that is bound to happen.
There's already a subquery in there. I'm saying this can still be done with one subquery, just in a different place and it returns the desired results.