你可以试试这个。我在没有测试的情况下写的(我现在必须回家)。明天我可以帮你做任何错事。
SELECT A.LOCATION
, A.T_Inspections*B1.Rate as InspectionCost
, A.T_ServiceCall*B2.Rate as ServiceCallCost
, A.T_RegularHrs*B3.Rate as RegularHrsCost
, A.T_OTHrs*B4.Rate as OTHrsCost
, A.T_Inspections*B1.Rate + A.T_ServiceCall*B2.Rate+A.T_RegularHrs*B3.Rate+A.T_OTHrs*B4.Rate AS TOTAL_COST
FROM (SELECT LOCATION,
Sum(Inspections) AS T_Inspections,
Sum(ServiceCalls)AS T_ServiceCall,
Sum(RegularHrs)AS T_RegularHrs,
Sum(OTHRs) AS T_OTHrs
FROM Location
GROUP BY LOCATION) A
INNER JOIN RATES B1 ON A.LOCATION = B1.LOCATION AND B1.RATETYPE='Inspections'
INNER JOIN RATES B2 ON A.LOCATION = B2.LOCATION AND B2.RATETYPE='ServiceCalls'
INNER JOIN RATES B3 ON A.LOCATION = B3.LOCATION AND B3.RATETYPE='RegularHrs'
INNER JOIN RATES B4 ON A.LOCATION = B4.LOCATION AND B4.RATETYPE='OTHRs'