Search⌘ K
AI Features

Linear Interpolation

Explore how to handle missing data in SQL by applying linear interpolation. Understand how to use known data points and the interpolation formula to fill gaps in time series data, resulting in more natural and accurate data for analysis.

Overview

So far, we've seen how to fill in missing data using constant values or using a next or a last known value. These approaches are fairly simple, but they are a bit crude. There are other interpolation methods that fill in missing values in a more natural way.

Linear interpolation formula

Using linear interpolation filling missing values along a linear line between two known coordinates , we fill in missing values along a linear line between two known coordinates–-the last known value and the next known value.

This the formula to calculate linear interpolation:

y = y0 + (x - x0) * ((y1 - y0) / (x1 - x0))
Linear regression formula

The formula uses the following:

  • (x0, yo) , (x1, y1): The known points to interpolate by. ...