[Solved] Count SQL Query [closed]


Either of these will work. The second is better, but the first will show you how you can go about this when grouping by isn’t so straight-forward (or achievable).

SELECT 
    ISNULL(SUM(CASE WHEN OS_NAME = 'Linux' THEN 1 ELSE 0 END), 0) AS [Linux Servers],
    ISNULL(SUM(CASE WHEN OS_NAME = 'Windows' THEN 1 ELSE 0 END), 0) AS [Windows Servers]
FROM YourTable

SELECT OS_NAME, COUNT(*)
FROM YourTable
GROUP BY OS_NAME

solved Count SQL Query [closed]