CASE WHEN COUNT and GROUP BY
Posted on 2004-10-29
Greetings...I have the following statement that produces the expected results of id, Name and Points. However, I would like to 'sum' the count where names are duplicates. In other words, if a name has two entries (each having Points=1) I would like one entry where Points=2.
If I uncomment my GROUP BY I get only one name, but the Points value remains 1. What am I doing wrong? Thanks...Scott
CASE WHEN ((TrackingDateTime) IS NOT NULL AND (ReceivedByHESDateTime) IS NOT NULL) THEN 1 ELSE 0 END AS Points
FROM DocumentTracking a
INNER JOIN companies b ON (a.companyid = b.[id])
WHERE TrackingDateTime >= '10/28/03'
AND TrackingDateTime <= '10/28/04'
--GROUP BY b.[id], b.[name]
ORDER BY b.[name]