比较日期格式化为hh:mm:ss(看着头痛)
SELECT [Car] ,
DeviceNo ,
MIN([StateTime]) [StateTime] ,
MAX([EndTime]) [EndTime] ,
CAST(( DATEDIFF(SS, MIN([StateTime]), MAX([EndTime]))
/ 3600 ) AS VARCHAR(12)) + ':'
+ CAST(( ( DATEDIFF(SS, MIN([StateTime]),
MAX([EndTime])) - ( DATEDIFF(SS,
MIN([StateTime]),
MAX([EndTime]))
/ 3600 ) * 3600 )
/ 60 ) AS VARCHAR(12)) + ':'
+ CAST(( DATEDIFF(SS, MIN([StateTime]), MAX([EndTime]))
- ( DATEDIFF(SS, MIN([StateTime]),
MAX([EndTime])) / 3600 ) * 3600 )
- ( ( DATEDIFF(SS, MIN([StateTime]), MAX([EndTime]))
- ( DATEDIFF(SS, MIN([StateTime]),
MAX([EndTime])) / 3600 ) * 3600 )
/ 60 ) * 60 AS VARCHAR(12)) [datediff]
FROM [GPSTest].[dbo].[GPS_AccFire]
WHERE CAr = '粤S0972学'
GROUP BY [Car] ,
DeviceNo