News

SQL window functions provide extremely powerful and useful features that let you work with observations more easily. Different types explained here.
Oracle, SQL Server, Postgres, DB2 - the list goes on.<BR><BR>The reality is you have to restructure your query. A CTE isn't necessary, but will likely make the query more readable.
I would suggest you look at window functions, because typically they let you do the same thing in a much cleaner manner- but I always need a few experiments on real data to get them right.