我已经看过几个如何做到这一点的例子但是我不能退出与我的查询的连接 - 我将不胜感激任何帮助。
SELECT fe.NAME, fe.[FEE-EARNER], SUM(CONVERT(decimal(10, 2), CONVERT(numeric,t.[TIME-SPENT]) / 60)) AS Time, SUM(t.[CURR-VALUE]) AS WIP
FROM PUB1_TRTRANS t
LEFT JOIN PUB1_FEETR fe on t.[FEE-EARNER]=fe.[FEE-EARNER]
LEFT JOIN PUB1_DEPARTMENT d on fe.DEPARTMENT=d.[DEPARTMENT-CODE]
LEFT JOIN PUB1_MATDB m on t.[MT-CODE]=m.[MT-CODE]
LEFT JOIN
(
select [FEE-EARNER], sum([time-spent])/60
FROM dbo.PUB1_TRTRANS
WHERE ([ACT-CODE] <> N'BILL') AND (UNDONE = 0) AND ([ACT-CODE] <> N'CN')
and [YEAR]='2018'
and right([act-code], 1)<>'C'
and right([act-code], 1)<>'N'
and left([act-code], 1)<>'X'
and left([act-code], 3)<>'00N'
GROUP BY [FEE-EARNER]
) t2 ON t2.[fee-earner]=t.[fee-earner]
WHERE t.[bill-no] is null and t.undone=0 and t.billtx=0 AND t.[MT-CODE] IS NOT NULL
GROUP BY d.[DEPARTMENT-DESCRIPTION], fe.DEPARTMENT ORDER BY WIP DESC#
内部查询和外部查询都很好我只是无法加入[FEE-EARNER]字段中的两个。
答案 0 :(得分:0)
在我更仔细地重新阅读错误后,我发现在内部查询中我必须将其更改为总和([time-spent])/ 60 AS ChargeableTime - 即我没有给出我的总和([time-spent] )/ 60计算一个名字。