我不知道您的RDBMS,但这是来自SQL Server。另外,您的计算之一是错误的-02/09/2011-13/08/2011是20,而不是19。
create table dates ( myDate date)insert into datesvalues ({d '2011-08-13'}), ({d '2011-09-02'}), ({d '2011-09-10'}), ({d '2011-09-20'});with orderedDates as ( select ROW_NUMBER() OVER (order by myDate) as row, myDate from dates), datediffs as ( select DATEDIFF(dd, o2.myDate, o1.myDate) as diff from orderedDates o1 left outer join orderedDates o2 on o1.row = o2.row + 1)select AVG(cast(diff as decimal))from datediffswhere diff is NOT NULL
产生的结果是12.667:(20 + 8 + 10)/ 3。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)