• Having a CTE which is effectively defined as

    select * from (subquery)

    is somewhat bizarre too.

    You've been here long enough to know how to post questions - not only does your post omit DDL, sample data and desired results, it doesn't ask for anything either.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.