• You won't get the two queries to JOIN in the way that you are attempting to, unless each query works in isolation. The second query has aggregate functions but there's no GROUP BY, it's associated with the outer query. If all you want from the second query is those aggregate columns then there's almost certainly a better way of doing this. Can you give us some more detail?

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden