I'm trying to get a ratio of 'Good' values to the Total for a given ID. The query below works when I only use one ID for the IN clause. However when I add more than one ID, the Total ends up being for all IDs and not for a given ID. Is there a way to modify the SUM to make it ID specific? I should point out that ID is NOT a Primary Key. They can repeat. These totals are number of records. They are always integers.
SELECT ID,
COUNT (
CASE WHEN [Status] = 'Good'
THEN 1
END
) Good,
SUM(COUNT(*))over() as Total
FROM TABLE
WHERE ID IN ('ID1','ID2')
GROUP BY ID
If for say ID1 there are 45 records. 10 of them are Status Good. I want to return both 10 and 45 as individual values.
SUM(COUNT(*))over(partition by ID), agree with above speaker, why not provide some sample data, not many here are mindreaders and know tsqlCOUNT(*)