Craig mentions this in the piece, but I'll second it:
I fucking love CTE's for breaking apart ugly looking queries. They make everything significantly easy to read.
I fucking love CTE's for breaking apart ugly looking queries. They make everything significantly easy to read.