Multi-column Conditional Aggregation
问题 In SQL Server 2008. I have things that have components in one of two states, and the table looks like this: create table Things ( ThingName varchar(10), ItemNumber INT, ItemStatus varchar(10)); INSERT INTO Things ( ThingName, ItemNumber, ItemStatus) VALUES ('a', 1, 'red'), ('a', 2, 'red'), ('a', 3, 'blue'), ('b', 1, 'red'), ('b', 2, 'red'), ('b', 3, 'red'), ('b', 4, 'red'), ('c', 1, 'blue'), ('c', 2, 'blue'), ('c', 3, 'red'); The result I need for each Thing is 1) total number of items 2)