我有一个查询
select
*,
right(
convert(varchar, cast(JOB_DONE_time-JOB_send_time as datetime), 121),
12
) [TimeTaken]
from dbo.insert_data
order by job_id desc
这个查询的结果如下:
JOB_ID JOB_DONE_TIME JOB_SEND_TIME TimeTaken
--------- ----------------------- ----------------------- ------------
001-99900 2011-12-28 13:36:57.860 2011-12-28 13:36:57.593 00:00:00.267
001-99800 2011-12-28 13:36:57.843 2011-12-28 13:36:57.593 00:00:00.250
001-99700 2011-12-28 13:36:57.687 2011-12-28 13:36:57.547 00:00:00.140
001-99600 2011-12-28 13:36:57.593 2011-12-28 13:36:57.547 00:00:00.047
001-99500 2011-12-28 13:36:57.563 2011-12-28 13:36:57.437 00:00:00.127
001-99400 2011-12-28 13:36:57.547 2011-12-28 13:36:57.437 00:00:00.110
001-99300 2011-12-28 13:36:57.483 2011-12-28 13:36:57.377 00:00:00.107
001-99200 2011-12-28 13:36:57.437 2011-12-28 13:36:57.377 00:00:00.060
001-99100 2011-12-28 13:36:57.407 2011-12-28 13:36:57.187 00:00:00.220
001-99000 2011-12-28 13:36:57.360 2011-12-28 13:36:57.187 00:00:00.173
001-9900 2011-12-28 13:32:22.657 2011-12-28 13:32:22.500 00:00:00.127
通过这个查询,我已经得到了TimeTaken
列。现在我想计算timetaken
列的加和和平均值。我尝试使用SUM()
函数,但是它给我返回了一个错误:
Msg 8117, Level 16, State 1, Line 1 Operand data type varchar is invalid for sum operator.
我该如何计算???
varchar
列求和!如果你想要求和,这个列的数据类型必须是数字类型,像是INT
或其他数字类型。 - marc_s