SQLite Forum

How can I fill a NULL with previous Data ?
Login
Or, using the same table and data, the correlated form:

```
   select ordering_column,
          coalesce(ip_24_temperature,
                   (
                      select ip_24_temperature
                        from weather_table
                       where ordering_column < o.ordering_column
                         and ip_24_temperature is not null
                    order by ordering_column desc
                       limit 1
                   ),
                   0
                  ) as ip_24_temperature,
          coalesce(ip_24_humidity,
                   (
                      select ip_24_humidity
                        from weather_table
                       where ordering_column < o.ordering_column
                         and ip_24_humidity is not null
                    order by ordering_column desc
                       limit 1
                   ),
                   0
                  ) as ip_24_humidity
    from weather_table as o
order by ordering_column
;
```

For swiftest performance (at the expense, as always, of disk space), add the following indexes:

```
create index idx_weather_temperature on weather_table (ordering_column, ip_24_temperature) where ip_24_temperature is not null;
create index idx_weather_humidity on weather_table (ordering_column, ip_24_humidity) where ip_24_humidity is not null;
```