I am brand new to SQL Server (like 10 mins). I have a test database that contains a few columns (Units, Date, Master ID, AVE Monthly Sales). The Average Monthly sales is empty.
Background: I import data from Excel files, the files are built from other files, and the average sales calculation time is Excel is driving me crazy, thus this post.
What I would like to do is populate the Average Sales column with the average Units for the past 6 months based on the date in the relevant row. i.e. if the date is 2016-06-31, I should get the average unit sales for that particular Master ID (Master ID is not my unique key - fyi) from the 2016-01-01 to and including the 2016-06-31.
As mentioned I am new to SQL, I am using SQL Server Express (running Locally), the data table (SALES
) has about 8m rows. I am not sure if a calculation like this should be done is SQL, but I would like to try so I can check if it is in anyway faster than my current approach (Excel).
It would be great if someone can explain this with an example.
Thank you. Mark.