操作数数据类型时间对于平均运算符无效...? [英] Operand data type time is invalid for avg operator...?

查看:23
本文介绍了操作数数据类型时间对于平均运算符无效...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在以下查询中使用 avg(time(4)) :

How can I avg(time(4)) in the following query:

  select top 10 avg(e.Duration) from TimeTable e

我收到以下错误:

操作数数据类型时间对于 avg 运算符无效.

Operand data type time is invalid for avg operator.

持续时间是类型 time(4) 如:

Duration is type time(4) such as:

Duration
-------------
00:00:10.0000

推荐答案

可以使用 DateDiff( ms, '00:00:00', e.Duration ) 将时间转换为整数毫秒数.将其用于您的聚合,然后将结果转换回,例如Cast( DateAdd( ms, 1234, '00:00:00' ) as Time ).

You can use DateDiff( ms, '00:00:00', e.Duration ) to convert the time into an integer number of milliseconds. Use that for your aggregate, then convert the result back, e.g. Cast( DateAdd( ms, 1234, '00:00:00' ) as Time ).

这篇关于操作数数据类型时间对于平均运算符无效...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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