下午全部
好的一直在尝试为员工构建任务摘要以下是我的内容:
SELECT CONCAT (Mpl.FName,' ',Mpl.SName) AS 'Name',
Ctt.TaskName AS 'Task',
Cts.Pickset,
SUM(omo.Qty) 'Total of tasks',
COUNT(Cts.TaskStart) 'Number of Tasks',
CAST(SUM(DATEADD(SECOND, DATEDIFF(SECOND, Cts.TaskStart, Cts.TaskEnd), 0)) AS TIME) AS 'Total Task Time'
FROM CHDS_Management.dbo.People Mpl
LEFT JOIN CHDS_Common.dbo.TaskScan Cts ON Cts.EmpID = Mpl.EmpNo
LEFT JOIN CHDS_Common.dbo.TaskType Ctt ON Ctt.TaskShort = Cts.Task
LEFT JOIN (SELECT picksetno, MAX(PicksetLineNo) AS 'Qty' FROM CHDS_Common.dbo.OMOrder GROUP BY PicksetNo) omo ON omo.PicksetNo = Cts.Pickset
WHERE Cts.TaskStart >= '2017-06-01 06:00:00'
AND Cts.TaskEnd <= '2017-06-23 02:00:00'
GROUP BY CONCAT (Mpl.FName,' ',Mpl.SName),
ctt.TaskName,
Cts.Pickse
我想看到什么
> Justin Greenwood
> Pick 00:01:03
> 123456 20/06/2017 13:45:45 20/06/2017 13:46:12 00:00:27
> 123457 20/06/2017 13:47:14 20/06/2017 13:47:24 00:00:10
> 123458 21/06/2017 15:17:25 21/06/2017 15:17:53 00:00:28
> Systems 00:00:12
> Systems 20/06/2017 13:45:05 20/06/2017 13:45:17 00:00:12
即使我无法深入研究,我也希望得到像
这样的东西Justin Pick 100(totel of the 3 tasks) 00:01:03 (time taken for all 3 tasks
Justin Systems 0 00:00:12
答案 0 :(得分:1)
您需要某种类型的报告系统才能获得您想要的第一个结果 - SQL只是不能那样工作。这是第二个结果。我不知道你总结了“3个任务的总和”,所以你需要提供更详细的答案。
SELECT CONCAT (
Mpl.FName
,' '
,Mpl.SName
) AS 'Name'
,Ctt.TaskName AS 'Task'
,Cts.Pickset
,SUM(/*whatever you are totaling*/) 'Total of tasks'
,COUNT(Cts.TaskStart) 'Number of Tasks'
,convert(varchar(8), dateadd(second, SUM(DATEDIFF(SECOND, Cts.TaskStart, Cts.TaskEnd)), 0), 108) AS 'Total Task Time'
FROM CHDS_Management.dbo.People Mpl
LEFT JOIN CHDS_Common.dbo.TaskScan Cts ON Cts.EmpID = Mpl.EmpNo
LEFT JOIN CHDS_Common.dbo.TaskType Ctt ON Ctt.TaskShort = Cts.Task
WHERE Cts.TaskStart >= '2017-06-01 06:00:00'
AND Cts.TaskEnd <= '2017-06-23 02:00:00'
GROUP BY CONCAT (
Mpl.FName
,' '
,Mpl.SName
)
,ctt.TaskName
,Cts.Pickset