Hi @ojmp2001 ojmp2001 ,
Welcome to Microsoft Q&A!
You could also try with SUM as below:
SELECT DISTINCT Origin_ID, Origin_Name,
Count(Status_ID) AS Total_status_count,
SUM(CASE WHEN Status_Color = 'Red' THEN 1 ELSE 0 END) AS Red_count
From #Temp
GROUP BY Origin_ID, Origin_Name
ORDER BY Origin_ID
OR
SELECT DISTINCT Origin_ID, Origin_Name,
Count(Status_ID) Over (Partition by Origin_ID Order by Origin_ID) Total_status_count,
SUM(CASE WHEN Status_Color = 'Red' THEN 1 ELSE 0 END) Over (Partition by Origin_ID Order by Origin_ID) Red_count
From #Temp
ORDER BY Origin_ID
Output:
Origin_ID Origin_Name Total_status_count Red_count
2 RCO 4 3
3 USA 2 1
4 CAN 1 0
By the way, the count of 'red' for 'CAN' could be 0 based on your sample data. Please help check again. Thanks.
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.