在满足参数时计算多行的时间

时间:2017-06-19 17:03:52

标签: sql sql-server sql-server-2008

嗨我想计算满足特定参数的多行的经过时间。这是我的查询

SELECT 
 EventDate AS 'Date'
,ID
,DeptCode 'DC'
,OpCode 'OC'
,ElapsedTime = convert(time(0),dateadd(second,datediff(second,StartTime,FinishTime),0)) 
,Units = SUM(Units)
,UPH = cast(isnull(sum(Units) / nullif(sum(datediff(minute,StartTime,FinishTime))*1.0,0),0.0)*60  as decimal(10,0))
FROM dbo.TimeLog WITH (NOLOCK)
WHERE EventDate = '06/15/17' AND DeptCode = 'ST' AND OpCode = 'BT' 
GROUP BY 
   EventDate, ID, DeptCode, OpCode, StartTime, FinishTime
ORDER BY  UPH DESC

结果如下......

Date    ID      DC  OC  ElapsedTime Units   UPH
6/15/17 2375278 ST  BT  00:48:00    3262    4077
6/15/17 2375278 ST  BT  03:15:00    4730    1455
6/15/17 2375278 ST  BT  00:12:00    NULL    0
6/15/17 2375278 ST  BT  00:30:00    NULL    0
6/15/17 2375278 ST  BT  00:30:00    NULL    0
6/15/17 2375278 ST  BT  00:45:00    NULL    0
6/15/17 2375278 ST  BT  03:20:00    NULL    0
6/15/17 2375278 ST  BT  00:40:00    NULL    0

我希望看到的是我的结果

Date    ID      DC  OC  ElapsedTime Units   UPH
6/15/17 2375278 ST  BT  10:00:00    7992    799

有人可以帮忙编写这个脚本吗?

1 个答案:

答案 0 :(得分:0)

@echo off
for /f "tokens=3 delims=<>" %%a in ('find "childElement.version" file.xml') do set "var=%%a"
echo %var%