Count the number of occurrences of certain values of TagName column I want to count the number of occurrences of different sensor rows in SQL, but I seem to be doing it wrong and seemingly I am not visualizing it correctly.
If I was doing this in pseudocode in a C style language, I would do it like this:
FOR i in range(taglist[i]):
    
    print(taglist[i], count(taglist[i]) )

I have been trying this:
SELECT COUNT(*)
FROM   (
           SELECT DISTINCT [TagName]
           FROM   [A2ALMDB].[dbo].[AlarmMaster]
           WHERE  (TagName LIKE '%Sensor%' OR GroupName LIKE'%Sensors%')
       ) a

It returns 66, but I want it to return the count of each of the distinct tagnames that are returned in SELECT ... FROM (...)a.
Can anyone help me with how I should be trying to get all the counts of my different sensor occurrences to total instead of a count of all the distinct tagnames?
Sounds like a simple group by:
select tagname, count(*)
from alarmmaster
where tagname like '%Sensor%'  
   or groupname like '%Sensor%'
group by tagname;