Results 1 to 6 of 6
  1. #1
    jmltinc is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Dec 2016
    Posts
    3

    Returning Difference of Count in Same Table

    Hi Folks,



    I have a single table containing parent test data and of the various fields are: ATE_PK (Primary Key), ATE_SERIAL (serial number), ATE_TIME_FINISHED (time test was completed), and ATE_STATUS (0=FAIL, 1=PASS).

    I want to get a First Pass Yield by dividing those units that failed on the first try (MIN(ATE_TIME_FINISHED)) and ATE_STATUS=0)
    by
    all units tested on first try (MIN(ATE_TIME_FINISHED)), grouping by ATE_SERIAL.

    Can anyone help with this query?

    Thanks,
    -John

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    You'll need a few queries,
    Q1: ID, min(date) ,where status=0
    Q2: Id, min(date)

    now you have the min dates,do the counts:
    Q3: join Q1 to the data via ID and get the count
    Q4: join Q2 to the data via ID ,get count

    Q5: using Q3 and Q4 to get percents.

  3. #3
    jmltinc is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Dec 2016
    Posts
    3
    Quote Originally Posted by ranman256 View Post
    You'll need a few queries,
    Q1: ID, min(date) ,where status=0
    Q2: Id, min(date)

    now you have the min dates,do the counts:
    Q3: join Q1 to the data via ID and get the count
    Q4: join Q2 to the data via ID ,get count

    Q5: using Q3 and Q4 to get percents.

    Thank you for your input. I can do that with VBA inside an event, but am really hoping for an inline query for a control...

    -J

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    What Ranman suggested would entail using query Q5, no VBA at all.

  5. #5
    jmltinc is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Dec 2016
    Posts
    3
    Quote Originally Posted by aytee111 View Post
    What Ranman suggested would entail using query Q5, no VBA at all.
    I'm sorry, but I do not understand.

    Q1 and Q2 return as expected. Joining Q1 (and I went no further) returns 2 records - not one:

    Data:
    ATE_PK ATE_SEQUENCE_FK ATE_SERIAL ATE_STATION ATE_STATUS ATE_START_TIME ATE_END_TIME
    7 10 161245837 13 0 12/11/2015 12/11/2016 3:13:03 PM
    8 10 161245837 13 0 12/12/2015 12/12/2016 3:13:03 PM
    9 10 161245847 13 1 12/12/2016 10:52:21 AM 12/12/2016 10:52:21 AM
    10 10 161245840 13 1 12/12/2016 11:24:01 AM 12/12/2016 11:24:01 AM
    11 10 161245839 13 1 12/12/2016 11:53:12 AM 12/12/2016 11:53:12 AM
    15 10 161245838 13 1 12/12/2016 1:31:13 PM 12/12/2016 1:31:13 PM
    16 10 161245834 13 1 12/12/2016 2:01:59 PM 12/12/2016 2:01:59 PM
    17 10 161245835 13 1 12/12/2016 2:27:04 PM 12/12/2016 2:27:04 PM
    18 10 161245837 13 1 12/12/2016 3:13:03 PM 12/12/2016 3:13:03 PM
    19 10 161245844 13 1 12/12/2016 3:36:30 PM 12/12/2016 3:36:30 PM

    SQL:
    SELECT ATE_ATE_TESTS.ATE_SERIAL, Min(ATE_ATE_TESTS.ATE_END_TIME) AS MinOfATE_END_TIME, Count(ATE_ATE_TESTS_1.ATE_PK) AS CountOfATE_PK
    FROM ATE_ATE_TESTS INNER JOIN ATE_ATE_TESTS AS ATE_ATE_TESTS_1 ON ATE_ATE_TESTS.ATE_PK = ATE_ATE_TESTS_1.ATE_PK
    WHERE (((ATE_ATE_TESTS.ATE_STATUS)=0))
    GROUP BY ATE_ATE_TESTS.ATE_SERIAL;


    Return:
    ATE_SERIAL MinOfATE_END_TIME CountOfATE_PK
    161245837 12/11/2016 3:13:03 PM 2


    What am I missing here???

    Thanks,
    -John

  6. #6
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Q1: get all records
    SELECT Table2.sn, Min(Table2.Time) AS MinOfTime FROM Table2 WHERE (((Table2.time) Is Not Null)) GROUP BY Table2.sn;

    Q2: get failed
    SELECT Table2.sn, Table2.Time FROM q1 INNER JOIN Table2 ON (q1.MinOfTime = Table2.time) AND (q1.sn = Table2.sn) WHERE (((Table2.pf)=False));

    Q3: get count of fails
    SELECT Count(q1.sn) AS CountOfsn FROM q1;

    Q4: get count of all
    SELECT Count(q2.sn) AS CountOfsn FROM q2;

    Q5: get yield
    SELECT q4.CountOfsn / q3.CountOfsn * 100 AS yield FROM q3, q4;

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 09-11-2014, 09:34 AM
  2. Returning a specific count on a web form
    By Bobwords in forum Forms
    Replies: 9
    Last Post: 07-07-2014, 12:58 PM
  3. Count is returning the wrong count.
    By khughes46 in forum Reports
    Replies: 2
    Last Post: 05-26-2014, 12:46 PM
  4. Replies: 6
    Last Post: 04-26-2012, 10:00 PM
  5. Count difference between two dates
    By Costa in forum Forms
    Replies: 3
    Last Post: 03-09-2010, 10:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums