我有这个查询
select
substring((convert(varchar, PostTime, 120)), 1, 11),
AccountNumber,
sum(Cast(datediff(ss, TranTime, AuthProcessedTime) as money)) / COUNT(1) AverageTime,
COUNT(1) NumberOfCount
from
AuthTransactions WITH (NOLOCK)
group by
substring((convert(varchar, PostTime, 120)), 1, 11), AccountNumber
在此查询中AverageTime
以秒为单位。但我希望以下列格式HH:MM:SS.msmsms
看到它,因为大多数时间结果都以毫秒为单位。那么有可能以这种格式看到结果吗?
提前致谢。
答案 0 :(得分:2)
试试这个:
SELECT
Convert(date, PostTime) PostDay
AccountNumber,
Avg(Datediff(ms, TranTime, AuthProcessedTime) * 1.0) AverageTime,
Count(*) NumberPerDay
FROM
dbo.AuthTransactions
GROUP BY
Convert(date, PostTime),
AccountNumber
我删除或更正了查询的几个问题:
char
数据类型的长度。DateDiff
和DateAdd
,或者由于您使用的是SQL 2008,因此可以转换为date
。答案 1 :(得分:0)
在datediff(ss,TranTime,AuthProcessedTime)
中
将ss更改为ms。
ms用于毫秒秒。
select substring((convert(varchar,PostTime,120)),1,11),
AccountNumber,
sum(Cast (datediff(ms,TranTime,AuthProcessedTime) as money)) / COUNT(1)
AverageTime,COUNT(1) NumberOfCount from AuthTransactions
WITH(NOLOCK) group by
substring((convert(varchar,PostTime,120)),1,11),AccountNumber