In my model I have the following query which average $probe values hour by our for the last day available in the database.
$connection=Yii::app()->db;
$command=$connection->createCommand("SELECT AVG($probe), TIME FROM tbl_sensors GROUP BY DATE(TIME), HOUR(TIME) ORDER BY ID DESC LIMIT 0, 24");
$dataReader=$command->query();
Now I’d like to modify this query to get the result for yesterday, the day before yesterday etc.
My first thought was to add a variable fed by the controller modify LIMIT parameters. Though the following:
SELECT AVG($probe), TIME FROM tbl_sensors GROUP BY DATE(TIME), HOUR(TIME) ORDER BY ID DESC LIMIT 24, 48
returns 48 values instead of 24. I don’t understand why is that?
Any pointers welcome
LIMIT 24, 48doesn’t mean from 24 to 48. it means from 24 to (24+48).if I say in another way, it starts from 24, get 48 records .
http://dev.mysql.com/doc/refman/5.1/en/select.html
but I recommend you to use
WHERE