SELECT AVG(period)
FROM (
SELECT TIME_TO_SEC(TIMEDIFF(@date_posted, date_posted)) AS period,
@date_posted := date_posted
FROM (
SELECT @date_posted := NULL
) vars,
messages
ORDER BY
date_posted
) q