Is it possible to combine multiple CTEs in single query with arel? I am looking for way to get result like this:
arel
WITH \'cte1\' AS ( ... ), WITH
Yes. You don't repeat the WITH. You just use a comma:
WITH
WITH cte1 AS ( ... ), cte2 AS ( ... ), cte3 AS ( ... ) SELECT ... FROM 'cte3' WHERE ...
And: Only use single quotes for string and date constants. Don't use them for column aliases. They are not allowed for CTE names anyway.