Operand data type time is invalid for avg operator…?

后端 未结 4 1475
渐次进展
渐次进展 2020-12-11 16:16

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

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

I\'m getting the following error:

4条回答
  •  长情又很酷
    2020-12-11 17:09

    Addition to HABO's and Rafi's answers.

    For my case, I had to cast the value of the DATEDIFF to a bigint because my value grew too large and caused an arithmetic overflow error.

    CAST(DATEADD( ms,AVG(CAST(DATEDIFF( ms, '00:00:00', ISNULL(e.Duration, '00:00:00')) as bigint)), '00:00:00' )  as TIME) as 'avg_time'
    

提交回复
热议问题