用T-SQL求和并转换时间

时间:2019-02-13 14:39:44

标签: sql sql-server tsql sum

我正在尝试汇总一次会议中完成所有案件所需的总时间。每个案例的时间以秒为单位存储在[时间]栏中。如何将其求和并转换为hh:mm:ss格式?

我的代码如下:

client = boto3.client('rekognition')

image_path='images/4.jpeg'
image = Image.open(image_path)

stream = io.BytesIO()
image.save(stream,format="JPEG")
image_binary = stream.getvalue()

response = client.detect_text(Image={'Bytes':image_binary})

结果应如下所示:

[sessionno] as session_no
,count ([id]) as No_Items
,(convert (varchar, dateadd (ms, (sum([time])) * 1000, 0), 108)) as total_work_time

相反,我收到了:

session_no | No_items | total_work_time
112138          8         00:35:12
112583          0         00:00:00
212558          1         00:00:17

1 个答案:

答案 0 :(得分:1)

SQL的一些更正

 SELECT [sessionno] as session_no,
        count ([id]) as No_Items,
        dateadd (ss, sum([time]), cast('00:00:00' as time)) as total_work_time
 FROM your_table
 GROUP BY [sessionno]

但是,请注意时间数据类型可能为overflow