可能重复:
Calculate open hours
到目前为止,我正在使用SQL查询来计算投诉的“开放时间”complaintdate
。
Select datediff(hour,
Convert(DateTime,
Convert(DateTime,
Convert(nVarChar, cast(complaintdate as datetime), 101)
) + '' +
Convert(varchar, complainttime, 114)
),
dateadd(mi, 330, GETUTCDATE())
) as [Open Hours] from complaintregister
获取专栏
Open Hours
15139
15070
15070
15070
15070
100
300
200
400
我希望开放时间只有500多个
答案 0 :(得分:1)
这是一个简单的方法:
select * from ( Select datediff(hour,
Convert(DateTime,
Convert(DateTime,
Convert(nVarChar, cast(complaintdate as datetime), 101)
) + '' +
Convert(varchar, complainttime, 114)
),
dateadd(mi, 330, GETUTCDATE())
) as [Open Hours] from complaintregister ) t where t.[Open Hours]>500