I’m writing a SQL in Oracle. In the SQL, I have the same subquery used twice. I’m trying to find the best way for replacing such common subquery or queries that get reused.
I was thinking to create a view for the subquery but I’m not allowed to do so. Global temporary tables could be other solution but I came to know that such tables aren’t really for creating and dropping on the fly.
You could use a view or a global temporary table, but it’s often better to use a WITH clause, e.g.: