Note that there are some explanatory texts on larger screens.

plurals
  1. POMYSQL QUERY replace NULL value in a row with average values
    primarykey
    data
    text
    <p>I'm using a mysql database to store huge amount of satellite data, and these datasets has many data-gaps. I would like to replace the NULL values with an 1 hour(or less) average around that point. So far I've found how to replace the NULL value with the previous known value:</p> <pre><code>UPDATE mytable SET number = (@n := COALESCE(number, @n)) ORDER BY date; </code></pre> <p>from this post: <a href="https://stackoverflow.com/questions/1345065/sql-query-replace-null-value-in-a-row-with-a-value-from-the-previous-known-value">SQL QUERY replace NULL value in a row with a value from the previous known value</a></p> <p>My table looks like</p> <pre><code>+---------------------+--------+ | date | P_f | +---------------------+--------+ | 2001-01-01 20:20:00 | 1.88 | | 2001-01-01 20:25:00 | NULL | | 2001-01-01 20:30:00 | NULL | | 2001-01-01 20:35:00 | 1.71 | | 2001-01-01 20:40:00 | NULL | | 2001-01-01 20:45:00 | NULL | | 2001-01-01 20:50:00 | NULL | | 2001-01-01 20:55:00 | 1.835 | | 2001-01-01 21:00:00 | 1.918 | | 2001-01-01 21:05:00 | 1.968 | | 2001-01-01 21:10:00 | 2.004 | | 2001-01-01 21:15:00 | 1.924 | | 2001-01-01 21:20:00 | 1.8625 | | 2001-01-01 21:25:00 | 1.94 | | 2001-01-01 21:30:00 | 2.0375 | | 2001-01-01 21:35:00 | 1.912 | </code></pre> <p>I'd like to replace the NULL values with average values around that datetime. For instance I'd like to replace ,</p> <pre><code>| 2001-01-01 20:50:00 | NULL | </code></pre> <p>with an average around </p> <pre><code>select AVG(P_f) from table where date between '2001-01-01 20:30' and '2001-01-01 21:10'; </code></pre> <p>Paul</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload