SELECT avg(con_hits) as avg_hits FROM content WHERE con_type = 1 AND con_posttime < $twelve_hrs_ago AND con_refresh = 0 ORDER BY con_posttime DESC LIMIT 100
I would like it to go to the first record that was posted at least 12 hours ago (denoted by the $twelve_hrs_ago variable which has the suitable timestamp), and take the average of the con_hits column, for the next 100 records. In my example, it disregards the LIMIT, and takes the average of every record in the table.
Is there a way to bypass that?
LIMITis applied to the resultset, afterAVGis calculated. You can do what you want, with a subselect:You can use the database to calculate the time offset too. Replace
$twelve_hrs_agoabove with: