|How to get frequency for a subset of first names?
Execute the following T-SQL example scripts in Microsoft SQL Server Management Studio Query Editor to demonstrate how to obtain frequency only for a subset of first names.
-- SQL common table expression - t-sql cte - MSSQL group by count
AS (SELECT FirstName,
NameFrequency = count(* )
WHERE FirstName IN ('Peter','Jane','Kathleen','John')
GROUP BY FirstName
NameFrequency = 0
WHERE FirstName NOT IN ('Peter','Jane','Kathleen','John')
GROUP BY FirstName)
ORDER BY NameFrequency DESC,
/* Partial results
A. Scott 0