无法通过描述获得总和

时间:2018-09-27 16:04:52

标签: mysql sorting

DECLARE @CurrentWk DATE = CAST(DATEADD(day,(-1*DATEPART(DW,GETDATE()))+2,GETDATE()) AS DATE 
SELECT  
sum (JobOpDtl.EstProdHours) as [ProdHours],  
JobOper.DueDate,  
JobOpDtl.ResourceGrpID,  
Resource.[Description] as [ResDes],  
CASE 
  WHEN CAST(DATEADD(day,(-1*DATEPART(DW,JobOper.DueDate))+2,JobOper.DueDate) AS DATE) < @CurrentWk THEN DATEADD(DAY, -7, @CurrentWk)
  ELSE CAST(DATEADD(day,(-1*DATEPART(DW,JobOper.DueDate))+2,JobOper.DueDate) AS DATE) 
END AS [DueWk]
FROM Erp.JobOpDtl

 JOIN Erp.JobOper ON  
JobOper.JobNum = JobOpDtl.JobNum  
AND JobOper.OprSeq = JobOpDtl.OprSeq

JOIN Erp.JobHead ON  
JobHead.JobNum = JobOper.JobNum

JOIN Erp.Resource ON  
Resource.ResourceGrpID = JobOpDtl.ResourceGrpID  
AND Resource.ResourceID = JobOpDtl.ResourceID

WHERE JobHead.JobClosed = '0'  
AND JobOper.OpComplete = '0'  
AND JobOper.AssemblySeq = '0'  
and JobOper.JobNum NOT LIKE '%-w%'

GROUP BY  
Resource.Description,  
JobOpDtl.ResourceGrpID,  
JobOper.DueDate

这正在拉结果,但我试图按星期和ResDes进行总结。例子
5.00,2018-10-04,NCFP-T,3-AXIS ROUTER-TULSA,2018-10-01
0.50,2018-10-05,NCFP-T,3-AXIS ROUTER-TULSA,2018-10-01

应该是
5.50,2018-10-04,NCFP-T,3-AXIS ROUTER-TULSA,2018-10-01

我很茫然。谢谢大家的帮助。

0 个答案:

没有答案