Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Not the most elegant I admit but it should get you what you want.</p> <p>I'm not sure how you want to handle those NULL values that have an hour average of NULL. In the example below these will get updated to -1.</p> <pre><code>create table myTable (myDate datetime not null, P_f decimal(10,5) default null ); insert into myTable(myDate,P_f) values ('2001-01-01 20:20:00',1.88); insert into myTable(myDate,P_f) values ('2001-01-01 20:25:00',NULL); insert into myTable(myDate,P_f) values ('2001-01-01 20:30:00',NULL); insert into myTable(myDate,P_f) values ('2001-01-01 20:35:00',1.71); insert into myTable(myDate,P_f) values ('2001-01-01 20:40:00',NULL); insert into myTable(myDate,P_f) values ('2001-01-01 20:45:00',NULL); insert into myTable(myDate,P_f) values ('2001-01-01 20:50:00',NULL); insert into myTable(myDate,P_f) values ('2001-01-01 20:55:00',1.835); insert into myTable(myDate,P_f) values ('2001-01-01 21:00:00',1.918); insert into myTable(myDate,P_f) values ('2001-01-01 21:05:00',1.968); insert into myTable(myDate,P_f) values ('2001-01-01 21:10:00',2.004); insert into myTable(myDate,P_f) values ('2001-01-01 21:15:00',1.924); insert into myTable(myDate,P_f) values ('2001-01-01 21:20:00',1.8625); insert into myTable(myDate,P_f) values ('2001-01-01 21:25:00',1.94); insert into myTable(myDate,P_f) values ('2001-01-01 21:30:00',2.0375); insert into myTable(myDate,P_f) values ('2001-01-01 21:35:00',1.912); insert into myTable(myDate,P_f) values ('2001-01-02 20:40:00',NULL); -- Insert copy of null value P_f rows into myTable with 1 hour average about myDate insert into myTable (myDate,P_f) select t.myDate,ifnull((select avg(P_f) from myTable t1 where t1.myDate between t.myDate - interval 1 hour and t.myDate +interval 1 hour),-1) as hourAvg from myTable t where t.P_f is null; -- delete rows where P_f is null delete from myTable where P_f is null; </code></pre>
 

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