Count instances of multiple invoices and pivot on location
问题 The embarassing fiddle for the entire question can be found here. Basically I have three tables containing invoice information: CREATE TABLE billing ([bill_id] varchar(5), [bill_reference_id] varchar(8), [bill_date] date, [billing_type] varchar(1)) CREATE TABLE billing_detail ([bill_id] varchar(5), [accpac_category_type] varchar(1), [location_id] varchar(1)) CREATE TABLE locations ([location_id] varchar(1), [location] varchar(50)) ; Invoices can have two billing_types I and C (invoice and