An Easy Guide to Master Moving Average and Running Total in SQL | by Iffat Malik Gore | Jul, 2023

Unlocking Advanced in SQL

Iffat Malik Gore
Towards Data Science

If you work with , you’ve likely come across the terms ‘Moving Average’ and ‘Running Total’ quite frequently. Data often refer to the saying,

“ The is your friend. “

Having a clear understanding of the trend is crucial for making accurate forecasts and informed decisions. However, determining the trend is not always a straightforward task. This is where a simple moving average comes into the picture. By tracking the trend over a defined time period, it helps identify and mitigate noise while smoothing out data fluctuations. This technique enhances our ability to analyse patterns effectively and make reliable predictions.

Before diving into the demonstration, let’s familiarise ourselves with a few key terms.

What is Moving Average?

Moving Average is also known as Rolling Average, Running Average, or Rolling Mean. You calculate it by taking the average of a set of values over a specific period of time.

It provides a standardised and concise way to summarise and analyse data, revealing the overall trend and enabling data professionals, and to draw meaningful conclusions based on , central tendency, variability, and within a dataset.

Many people are enthusiastic about tracking their step counts. So, let’s use this to understand the concept of moving average. Let’s say, instead of focusing solely on the number of steps we take each day, we calculate a 7-day moving average of step count.

To calculate the 7-day moving average, add the step counts from the past seven days and divide the sum by 7.

by author

Considering the calculation in the above image, the moving average of 7928.57 steps gives us a better understanding of our overall activity levels. By comparing this average to the daily step count, we can see whether we consistently meet or surpass the average.

Source link