I found a solution for those in future searching for it.
$sql = "SELECT ROUND(AVG(SUMR),1) as AVGR from
(SELECT SUM(MAXR) as SUMR, datum from
(SELECT MAX(A.R) as MAXR, Date(A.DateTime) as datum from weatherdata as A
where DATE(A.DAteTime)> Date('2016-12-31')
and DAYOFYEAR(A.DateTime)<=$daynumber
group by DATE(A.DateTime)) as B group by YEAR(datum)) as C";
In PhP I start by defining a variable $daynumber which gives the day number of the year (this as otherwise intervals are not compatible across years) with
$daynumber=date(z)
I take the average starting after 31-12-2016 (i.e. from 2017 onwards). The database table is weatherdata
good luck!