a simple question for all you SQL gurus: I have the following table structures (not including irrelevant columns);
Area -- AreaID, AreaName
District -- DistrictID, DistrictName, AreaID
Office -- OfficeID, OfficeName, DistrictID
Customer -- CustomerID, OfficeID
I need to be able to get a count of customers in offices, grouped by Area and then by Distric, given an AreaID as input parameter;
DistrictID1 DistrictName1 Count_of_customers
DistrictID2 DistrictName1 Count_of_customers
...
and a count of customers grouped by AreaID (no input parameter)
Area1 Count_of_customers
Area2 Count_of_customers
....
A query like this should do the trick
For the count of customers in the area, you can do the following