I have two tables simplified as shown below.
CREATE TABLE value( Timestamp DATETIME2, Value float NOT NULL, PRIMARY KEY(Timestamp) ); CREATE TABLE location( Timestamp DATETIME2, Position GEOMETRY NOT NULL, PRIMARY KEY(Timestamp) );
Running a simple LEFT JOIN, for example:
SELECT V.Timestamp, V.Value, L.Position FROM value V LEFT JOIN location L ON V.Timestamp = L.Timestamp;
This gives all values, but there is NULL if there is no exact match on the Timestamp
.
My goal is to get the interpolated position for each value in the value table. I need to somehow interpolate the values ββin my query, and it is here that I am stuck.
EDIT: I have since discovered that I can add a CASE statement to check for NULL
SELECT V.Timestamp, V.Value, CASE WHEN L.Position IS NULL THEN (<something clever here>) ELSE L.Position END As Position FROM value V LEFT JOIN location L ON V.Timestamp = L.Timestamp;
source share