Page 1 of 1

get values 10 by 10 days

Posted: Thu May 23, 2002 1:11 pm
by rwar
Hi.

How can I get values from mysql ten by ten days? The structure of the table is like this:
date tmax tmin rain
1960-01-01 25.5 23.1 12.0
1960-01-02 24.3 22.5 0.0
...
1960-02-01 ...
...
1960-03-01 ...
...
1961-01-01 26.4 21.4 10.3
1961-01-02 ...
...

The data are arranged day by day, as you can see. I can get those values year by year and, for each year, month by month, with the following code.

Code: Select all

<?php
$result_temp = mysql_query( "SELECT AVG(( tmax + tmin ) / 2 )
        AS temp_avg FROM dados
        GROUP BY YEAR( data ), MONTH( data )" );
?>
But I could not get them like I said, 10 by 10 days (or 11, if month have 31 days).

Any help or suggestion I'd appreciate.

Regards,

rwar.

Posted: Thu May 23, 2002 9:16 pm
by volka
try

Code: Select all

<?php 
$startdate = date('Y-m-d');
$result_temp = mysql_query( "SELECT AVG(( tmax + tmin ) / 2 ) AS temp_avg FROM dados WHERE date >= "$startdate" AND date < "$startdate"+INTERVAL 10 day GROUP BY YEAR( data ), MONTH( data )" ); 
?>