oracle sql中的平均日期 [英] Averaging dates in oracle sql

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

问题描述

有没有办法在oracle中平均多个日期?平均没有任何好处。



谢谢。

解决方案

平均日期的定义是主观的,但您可以将您的日期转换为朱利安数字,然后将其平均为周围,然后转换为日期。

 创建表日期(dt DATE); 

插入到日期
值('24 -APR-2012');
插入日期
值('01-JAN-2012');
插入到日期
值('01-JAN-2013');
insert into dates
values('25 -DEC-1900');


选择to_date(round(avg(to_number(to_char(dt,'J')))),'J')
from dates;

这是SQL小提琴: http://sqlfiddle.com/#!4/98ce9/1


Is there a way to average multiple dates in oracle? avg doesn't do any good.

Thanks.

解决方案

The definition of an "average date" is subjective, but you could convert your dates to a Julian number, then average those, round it off, then convert back to a date.

create table dates (dt DATE);

insert into dates 
values ('24-APR-2012');
insert into dates 
values ('01-JAN-2012');
insert into dates 
values ('01-JAN-2013');
insert into dates
values ('25-DEC-1900');


select to_date(round(avg(to_number(to_char(dt, 'J')))),'J')
from dates;

Here's the SQL Fiddle: http://sqlfiddle.com/#!4/98ce9/1

这篇关于oracle sql中的平均日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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