我试图将两列的结果添加到下面我的查询中的“准时”列中,并根据总列进行计算。结果我想要的是这些列:
评估员 'OntimeSum' 'PastDueSum' 'Ontime + Pastdue' '%ontime'
我已经在下面的查询中有前三个,但我不知道如何做其他的,似乎无法弄清楚它们或在任何地方找到示例。
WITH AppraiserTurnTime AS
(SELECT (v.ContactLastName+ ', ' +v.ContactFirstName) AS Appraiser
,SUM(CASE WHEN oi.SubmittedDate <= oi.AssignedDate THEN 1 ELSE 0 END) AS OnTime
,SUM(CASE WHEN oi.SubmittedDate >= oi.AssignedDate THEN 1 ELSE 0 END) AS PastDue
FROM OrderItems oi
JOIN Vendors v ON v.VendorID = oi.VendorID
JOIN VendorClasses vc ON vc.VendorClassID = v.VendorClassID
WHERE vc.VendorClassID in (6, 3)
GROUP BY ContactFirstName,v.ContactLastName)
SELECT * FROM AppraiserTurnTime