Computer Learning Zone CLZ Access Excel Word Windows

Winners are not people who never fail, but people who never quit.

-Arnold Schwarzenegger
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Visitor Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Aggregate Query Calculations
Camrin Bell 

3 years ago
How can I get access to calculate good producers based on test results for each producer? A good producer will have their last 30 shipments pass specifications. I want access to show me the current streak of good loads for each producer. A producer is a 3 part variable: 'company name' & 'city' & 'state/province'.
I can get access to identify a good load and bad load and the dates of shipments are in the database.
Kevin Robertson  @Reply  
          
3 years ago
Screenshots?
Kevin Yip  @Reply  
     
3 years ago
This is not a trivial problem, and we need some advanced query technique.  Basically, you need a query that returns the top 30 records for each producer if the records are sorted by producer, then in descending order by inspection date; then you check if all those 30 records indicate passed inspections.

The query to select top 30 records is below, but it only works for one producer at a time.  If the producers are identified by ID 100, 200, 300, etc., then you have to make a query for every one of them:

     SELECT TOP 30 ProductID, DateInspected, Passed FROM InspectionsT WHERE ProducerID = 100;
     SELECT TOP 30 ProductID, DateInspected, Passed FROM InspectionsT WHERE ProducerID = 200;
     SELECT TOP 30 ProductID, DateInspected, Passed FROM InspectionsT WHERE ProducerID = 300;
     Etc.
    
So how do we do this in one fell swoop?  You need to use a nested query, i.e. a query within a query.

Suppose your inspection records are in a table named InspectionsT that looks like Figure 1 below.  Each inspection is identified by a unique primary key PKID.  To simplify my presentation a bit, let's say we want to check only the last 5 inspections for each producer.  In this table, producer 100 passed the last 5 inspections.  Producer 101 only passed the last 1 inspection, on 2/25/23.  Producer 102 passed the last 8 inspections.  Producer 103 is relatively new and only did 4 inspections so far, all passed.  So in this example, you want Access to tell you only producer 100 and 102 passed their 5 previous inspections.

First, you need to make a query to return the last 5 inspections, pass or fail, of each producer.  Figure 2 below shows this query in SQL view and design view.  It is a "nested query" that also uses "table alias", two subjects that are quite advanced and involved.  Other posters may point you to the courses on this site so you can see what level they belong to.  The result of this query is as shown: all past 5 inspections of 100, 101, and 102 are listed, and 103 only has 4 inspections because that's all it has.

Based on results from the above query, you then need to make another query that counts the number of passes for each producer, and returns only the producers with 5 passes.  This is also done via a nested query that uses a table alias, shown in Figure 3 below.

I will post some more here shortly to help you unpack all this a little more.
Kevin Yip  @Reply  
     
3 years ago

Kevin Yip  @Reply  
     
3 years ago

Kevin Yip  @Reply  
     
3 years ago

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Visitor Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 4/30/2026 10:28:34 AM. PLT: 0s