获取 SQL 中时间之间的平均时间 [英] Get average time between times in SQL

查看:61
本文介绍了获取 SQL 中时间之间的平均时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不知道该怎么做.

I'm really clueless as how to do this.

说我的桌子看起来像这样:

Say my table looks like so:

MESSAGES
- id
- date_posted
- content

如何获得帖子之间的平均时间?(发布日期)

How do I get the average time between postings? (date_posted)

推荐答案

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

这篇关于获取 SQL 中时间之间的平均时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆