Count the number of building IDs
select count ( id ) from buildings
add a column for company id
select count ( * ), t1.company_id, t1.building_id from office_locations as t1 join buildings as t2 on t1.building_id = t2.id join companies as t3 on t1.company_id = t3.id group by t1.building_id
list the number of unique building ids for each company id
select t1.company_id, count ( distinct t1.building_id ) from office_locations as t1 join buildings as t2 on t1.building_id = t2.id join companies as t3 on t1.company_id = t3.id group by t1.company_id
add a column for company name
select t1.company_id, t3.name, count ( distinct t1.building_id ) from office_locations as t1 join buildings as t2 on t1.building_id = t2.id join companies as t3 on t1.company_id = t3.id group by t1.company_id