平均时间(nvarchar) [英] average of time ( nvarchar)

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

问题描述

我的表包含一个名为P_Time的列。有持续时间的(例如:

01:30:45,

03:45:00,
$ b $ 00 00:43 :34,

04:55:06,

00:54:00,

23:13:09

和SO ON)..但是P_Time是nvarchar(50)数据类型...但我的问题是如何使用查询找出所有这些记录的平均时间..

解决方案

尝试:

  SELECT  AVG(DATEDIFF(第二,'  0:0:0' CONVERT  time ,P_Time, 108 ))) FROM  TimeTab 





但是将时间存储起来会更好,更好的想法 - 使用它比使用字符串更容易,更安全


My table contains a column called P_Time. which has time duration''s like (Ex :
01:30:45,
03:45:00,
00:43:34,
04:55:06,
00:54:00,
23:13:09
and SO ON).. But P_Time is of nvarchar(50) datatype... But my question how can i find out the average time of all this records using a query..

解决方案

Try:

SELECT AVG(DATEDIFF(second, '0:0:0',CONVERT(time, P_Time, 108))) FROM TimeTab



But it would be a much, much better idea to store times as times - it is much easier and safer to work with than strings.


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

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