Formula to count by a set criteria

Please see the attached spreadsheet that I am trying to create. From the information (lines 2 to 13) in the table I want to create four small tables, one for each building (a, b, c & d), with numeric totals to show the amount of Yes in each column (labelled 1 to 10). The idea being that from the overall data collected, I can then break it down by building also. I have looked through the help files and I just can't seem to find anything that quite fits the bill.
Basically I want to total up if, column N equals A then how many 1's are Yes, how many 2's etc. and then repeat for each building.