Link to home
Start Free TrialLog in
Avatar of flemingg62
flemingg62

asked on

Count number of Unique occurance of ONE field in and Access query

I have a Access Query that returns a lot of data (25,360 in current set) I  want to count how may Unique Building and Floors there are (In this Case 1 building and 2 floors) and I can't figure out how to do in within 1 query (I prefer not to create lots of  a sub query to count the Building, Floor etc... separately)

Attached is sample output I'm trying to achieve and a the query design

User generated imageUser generated image
-----------
SELECT [Lookup Current Surveys].[Adept Survey UID], [Lookup Current Surveys].[Accordant SUS UID], [Lookup Current Surveys].Instance, [Lookup Curent Project].Sector, Count([SUS Source - Survey Data - Srva].ID) AS Observations, Count([SUS Source - Survey Data - Locn].Building) AS [Building Count], Count([SUS Source - Survey Data - Locn].Floor) AS [Floor Count]
FROM [SUS Source - Survey Data - Locn] INNER JOIN (([Lookup Current Surveys] INNER JOIN [Lookup Curent Project] ON [Lookup Current Surveys].[Adept Survey UID] = [Lookup Curent Project].[Adept Survey UID]) INNER JOIN [SUS Source - Survey Data - Srva] ON [Lookup Current Surveys].[Accordant SUS UID] = [SUS Source - Survey Data - Srva].Survey) ON [SUS Source - Survey Data - Locn].Code = [SUS Source - Survey Data - Srva].Location
GROUP BY [Lookup Current Surveys].[Adept Survey UID], [Lookup Current Surveys].[Accordant SUS UID], [Lookup Current Surveys].Instance, [Lookup Curent Project].Sector;
SOLUTION
Avatar of als315
als315
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of flemingg62
flemingg62

ASKER

Thanks, that what I figured
If you prepare sample DB, we can try to solve your problem
use the query you have, then do something like:

SELECT Count(SQ.*) as DistinctBuildingFloors
FROM (SELECT DISTINCT Building, Floor FROM yourQuery) as SQ

Well, that wouldn't quite work, because that query is already doing a group by and counting the building/floors, but you could probably use that right most table (query) as the source for the subquery above.

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial