如何在sql中编写此查询?关于timediff

时间:2014-07-16 07:33:30

标签: asp.net sql

starttime                  endtime

2013-01-23 06:49:00     2013-01-23 06:50:00

采用此格式的数据类型' DateTime'

Mysql查询

select timediff(max(endtime),min(starttime)) as t1,totalduration from dmaconf1 where refconfuuid ='007f40bd-ed70-4e7f-aa47-ba1ab12e5734'  and userid ='Piyush_Jain'

输出

t1                totalduration

-838:59:59         00:09:00 

MSSQL

select timediff(max(endtime),min(starttime)) as t1,totalduration from dmaconf1 where refconfuuid ='007f40bd-ed70-4e7f-aa47-ba1ab12e5734'  and userid ='Piyush_Jain'

错误

  

Msg 195,Level 15,State 10,Line 1' timediff'不是公认的   内置函数名称。

1 个答案:

答案 0 :(得分:1)

在MS SQL中,您应该使用datediff函数http://msdn.microsoft.com/en-us/library/ms189794.aspx

select datediff(s,max(endtime),min(starttime)) as t1,totalduration from dmaconf1 where refconfuuid ='007f40bd-ed70-4e7f-aa47-ba1ab12e5734'  and userid ='Piyush_Jain'