Hot answers tagged

3

If you don't have access to window-functions, you can use a subquery: SELECT Letter_Copy_ID , Letter_ID , ( SELECT COUNT(1) FROM T AS T2 WHERE T1.Letter_ID = T2.Letter_ID ) AS Letter_Copy_Count FROM T AS T1 If you have access to window functions: SELECT Letter_Copy_ID , Letter_ID , COUNT(1) OVER (PARTITION BY ...


1

With the limited information given, the easiest solution would be using a stored procedure and splitting up the CTE's in temporary tables. CTE's are not materialized so your view is in fact one big convoluted query. Bigger queries are harder to optimize. Splitting it up gives the optimizer some breathing room in optimization. An example with 2 temporary ...


Only top voted, non community-wiki answers of a minimum length are eligible