Oracle找到两个时间戳记的平均值 [英] Oracle find average of two timestamps

查看:233
本文介绍了Oracle找到两个时间戳记的平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看不到这是什么,但是我似乎找不到任何解决方案.日期已完成,但我看不到它可以在TIMESTAMP上使用.

I don't see hwo this is that ahrd, but I can't seem to find the solution anywhere. It's done for dates, but I can't see to make it work for TIMESTAMP.

我正在尝试

select avg(last_timestmp - ref_timestmp) as average from param

它不断告诉我这不是一个有效的数字,我得到了.但是,如何使它成为有效数字?我尝试了提取和其他一些东西,但似乎没有任何效果.

It keeps telling me it's not a valid number, which I get. But how do I make it a valid number? I have tried extract and a bunch of other stuff but nothing seems to work.

我希望以秒为单位的平均值.百分之一秒将是.01,而6小时将是21600

I want the average in seconds. one hundredth of a second would be .01 and 6 hours would be 21600

谢谢!

推荐答案

您可以使用EXTRACT以秒为单位提取零件并将其相加,然后计算平均值:

You can use EXTRACT to get out the parts as seconds and add them up then calculate your average:

select
    avg(extract(second from intrvl)
        + extract(minute from intrvl) * 60
        + extract(hour from intrvl) * 60 * 60
        + extract(day from intrvl) * 60 * 60 * 24) average
from (
    select (last_timestmp - ref_timestmp) intrvl 
    from param
)

这篇关于Oracle找到两个时间戳记的平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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