Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    amaro.neto is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    20

    Thank you very much for your help, you're a good person Orange, thank you. That is exactly what I need. I'll try to study more database relationships to make better DBs to improve our reports. But, for now, I'll work on the solution that you provided here.
    Thank you!

  2. #17
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I have done some additional testing this morning (fresh start).
    I devised the following SQL to identify the PercentS of each Bug/Bicho * ATB combination. This does not require the separate table. Try this SQL on your existing database. My testing was all done with your latest posted database.

    The SQL for query Q_PercentSForEachBugATBCombo

    Code:
    SELECT Bicho.NomeBicho
        ,ATB.Nome
        ,Sum([Union_Alias].R_count) AS RNum
        ,Sum([Union_Alias].S_count) AS SNum
        ,Round(Snum / (Rnum + SNum) * 100, 2) AS PercentS
    FROM (
        (
            SELECT TesteATB.ATBId
                ,TesteBicho.BichoId
                ,TesteATB.SensId AS ResR
                ,Count(TesteATB.TesteATBId) AS R_Count
                ,0 AS S_count
            FROM TesteBicho
            INNER JOIN TesteATB ON TesteBicho.TesteBichoId = TesteATB.TesteBichoId
            WHERE (((TesteATB.[sensid]) = "R"))
            GROUP BY TesteATB.ATBId
                ,TesteBicho.BichoId
                ,TesteATB.SensId
            
            UNION
            
            SELECT TesteATB.ATBId
                ,TesteBicho.BichoId
                ,TesteATB.SensId AS ResS
                ,0 AS R_count
                ,Count(TesteATB.TesteATBId) AS S_Count
            FROM TesteBicho
            INNER JOIN TesteATB ON TesteBicho.TesteBichoId = TesteATB.TesteBichoId
            WHERE (((TesteATB.[sensid]) = "S"))
            GROUP BY TesteATB.ATBId
                ,TesteBicho.BichoId
                ,TesteATB.SensId
            ) AS Union_Alias INNER JOIN Bicho ON [Union_Alias].BichoId = Bicho.BichoId
        )
    INNER JOIN ATB ON [Union_Alias].ATBId = ATB.ATBId
    GROUP BY Bicho.NomeBicho
        ,ATB.Nome;
    Here is part of the output from this query.

    Click image for larger version. 

Name:	Q_PercentSForEachBugATBCombo_Output.PNG 
Views:	33 
Size:	59.4 KB 
ID:	37268


    Good luck.
    Last edited by orange; 02-08-2019 at 03:46 PM. Reason: spelling

  3. #18
    amaro.neto is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    20
    Wow, that worked brilliantly! You're the man!
    I'll study that code to understand what you did. But it is working very well. Thank you!

  4. #19
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Happy to help. Good luck with your project.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 11-12-2015, 01:15 PM
  2. Replies: 3
    Last Post: 04-18-2015, 09:06 PM
  3. CrossTab query Count() doesn't match.
    By elena in forum Queries
    Replies: 5
    Last Post: 05-13-2014, 12:24 PM
  4. Replies: 5
    Last Post: 06-11-2013, 12:11 PM
  5. Totals Query Record Count with Criteria
    By rmoreno in forum Queries
    Replies: 3
    Last Post: 06-07-2013, 09:16 AM

Tags for this Thread

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