计算每天两个日期时间字段之间的平均时差

编程入门 行业动态 更新时间:2024-10-23 15:21:06
本文介绍了计算每天两个日期时间字段之间的平均时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个出租车数据库,其中有两个日期时间字段 BookedDateTime和 PickupDateTime。客户需要知道从预定出租车到驾驶员实际接客的平均等待时间。

I have a taxi database with two datetime fields 'BookedDateTime' and 'PickupDateTime'. The customer needs to know the average waiting time from the time the taxi was booked to the time the driver actually 'picked up' the customer.

数据库中有很多行,覆盖了几个月的数据。

There are a heap of rows in the database covering a couple of month's data.

目标是

所以一个简单的例子是:

So a super simple example would be:

BookedDateTime | PickupDateTime 2014-06-09 12:48:00.000 2014-06-09 12:45:00.000 2014-06-09 12:52:00.000 2014-06-09 12:58:00.000 2014-06-10 20:23:00.000 2014-06-10 20:28:00.000 2014-06-10 22:13:00.000 2014-06-10 22:13:00.000

2014-06-09((-3 + 6)/ 2)=平均值是00:03:00.000( 3分钟)

2014-06-09 ((-3 + 6) / 2) = average is 00:03:00.000 (3 mins)

2014-06-10((5 + 0)/ 2)=平均值是00:02:30.000(2.5分钟)

2014-06-10 ((5 + 0) / 2) = average is 00:02:30.000 (2.5 mins)

这可能还是我需要对代码进行一些数字运算(例如C#)?

Is this possible or do I need to do some number crunching in code (i.e. C#)?

任何指针都将不胜感激。

Any pointers would be greatly appreciated.

推荐答案

我认为这可以做到:

select Convert(date, BookedDateTime) as Date, AVG(datediff(minute, BookedDateTime, PickupDateTime)) as AverageTime from tablename group by Convert(date, BookedDateTime) order by Convert(date, BookedDateTime)

更多推荐

计算每天两个日期时间字段之间的平均时差

本文发布于:2023-10-23 22:44:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1522221.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   时差   平均   日期   两个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!