Home Forums SQL Server 2008 T-SQL (SS2K8) SQL QUERY Rows where TotalScore=@TotalScore in the range of value by using group by Date and Time RE: SQL QUERY Rows where TotalScore=@TotalScore in the range of value by using group by Date and Time

  • TheSQLGuru - Saturday, May 20, 2017 8:19 AM

    drew.allen - Wednesday, May 17, 2017 11:02 AM

    According to SUM (Transact-SQL), SUM() OVER(<partition> ORDER BY <order clause> ) is available starting in SQL-2008, which is what I was remembering.

    Drew

    I keep forgetting that you can do non-windowed aggregates with OVER/PARTITIONING/ORDER BY back that far!

    However, I am still not convinced the OP doesn't need a running total (i.e. 100 + 50 + 200 values would total 300+). If not they may be able to get by without the windowing necessary to do those.

    Sorry for taking so long to respond.  I started my new job on Monday.

    Adding an ORDER BY clause will create a running total (with the default frame of RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW).  If he doesn't need a running total, then he would just leave out the ORDER BY clause.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA