As suggested by Algunenano: qualify column names with the table/subquery/cte to avoid name clashing, and polish the code style a little.
As suggested by Algunenano: qualify column names with the table/subquery/cte to avoid name clashing, and polish the code style a little.