From: Plamen Ratchev on
Try this:

SELECT COUNT(DISTINCT L.LocationID) AS [LocRowCount],
SUM(L.RiskCount) AS [RiskCount],
SUM(C.TSI) AS [TSI]
FROM #Location AS L
JOIN
(SELECT LocationID, SUM(TSI) AS TSI
FROM #Coverage
GROUP BY LocationID) AS C
ON C.LocationID = L.LocationID;

--
Plamen Ratchev
http://www.SQLStudio.com
First  |  Prev  | 
Pages: 1 2
Prev: images in select query
Next: Build a date value