0
如何將多行添加到總行中?我正在嘗試添加兩行數據,並將數據輸出到一行中執行一項特定作業。我將輸出裁減到了一項工作,但是一旦我弄清楚如何將兩行合併爲一行,我將在輸出中放置多個工作。每個工作都有兩名員工,所以我將不得不將兩個員工的小時數加起來,以計算每個工作的總小時數。如何將總共多行添加到一行中
SELECT
TJ.intJobID
,TJ.strJobDescription
,TJS.strJobStatus
,SUM(TJE.intHoursWorked) AS intTotalHoursWorked
FROM
TJobs AS TJ
,TJobStatus AS TJS
,TJobEmployees AS TJE
,TEmployees AS TE
WHERE
TJ.intJobID = TJE.intJobID
AND TJ.intJobStatusID = TJS.intJobStatusID
AND TE.intEmployeeID = TJE.intEmployeeID
AND TJ.intJobID = 1
GROUP BY
TJ.intJobID
,TJE.intEmployeeID
,TJ.strJobDescription
,TJS.strJobStatus
,TJE.intHoursWorked
/*
Output I'm Getting
intJobID strJobStatus intTotalHoursWorked
1 Complete 50
1 Complete 42
Wanted Output
intJobID strJobStatus intTotalHoursWorked
1 Complete 92
*/
推廣使用顯式的' JOIN' sintaxis,Aaron Bertrand寫了一篇不錯的文章[踢壞壞習慣:使用舊式JOIN](http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to-kick -using-old-style-joins.aspx)。 –