Skip to content
Advertisement

How to escape several with in the query?

I need to refactor my query, but I have no idea, how to do this.

I can see several duplicates of using the same logic, but I continue to repeat this manner of querying from query to query, and I feel, that this kind of querying becomes my main frame of thinking of SQL and I don’t want this.

Could you show me more acceptable variant of this query, so I won’t repeat my way of thinking again?

Here it is

Advertisement

Answer

You are mixing CTE (Common Table Queries) with Subqueries, the beauty of the with clause is normally the readability:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement