Calculating Averages and Totals Between Dates

  • I am new developer in the SQL SERVER 2000 Environment. My question is as follws; I currently have a table named X. X contains a date field, fullName Field, and daily_totals Field. I would like to create a report that calculates the averages and sum (totals) on a weekly Basis. The problem i am encountering is how to mark the beginning and end of each week and get the calculations of averages and totals for each week since the beginning of the year. I am asking for your expert advice in this matter.

    Anthony Malone


    Anthony Malone

  • You might consider looking into using the DATAPART function and summing and averaging on the WEEK datepart.

    Gregory Larsen, DBA

    If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples

    Gregory A. Larsen, MVP

  • If you are summing, then you are already using a GROUP BY clause. To limit the results to only certain dates, you can use the HAVING clause:

    SELECT fullName,

    SUM(TOTALS)

    FROM X

    GROUP BY

    fullName

    HAVING date BETWEEN '1/1/2003' AND '1/1/2004'

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply