We help IT Professionals succeed at work.

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

59 Views
Last Modified: 2020-04-16
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

Design.PNGRestlts.PNG
-----------
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;
Comment
Watch Question

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks, that what I figured
CERTIFIED EXPERT

Commented:
If you prepare sample DB, we can try to solve your problem
Dale FyeOwner, Dev-Soln LLC
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2010

Commented:
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.

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.