Quantcast
Viewing latest article 3
Browse Latest Browse All 4

Answer by Luis Cazares for How can I get running totals of recent rows faster?

When dealing with such a small subset of rows returned, the triangular join is a good option. However, when using window functions you have more options that can increase their performance. The default option for window option is RANGE, but the optimal option is ROWS. Be aware that the difference is not only in the performance, but in the results as well when ties are involved.

The following code is slightly faster than the ones you presented.

SELECT TOP 10 seq    ,value    ,sum(value) OVER (ORDER BY seq ROWS UNBOUNDED PRECEDING) totalFROM Table_1ORDER BY seq DESC

Viewing latest article 3
Browse Latest Browse All 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>