Apache Spark SQL: Complex Queries with CTE (with clause)