Results 1 to 4 of 4
  1. #1
    kristaM79 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    2

    Counting only one type of record in a column

    Hi, I'm trying to create a query that counts the number of times one particular value appears in one column of a table and count the number of times another particular value appears in another column in the same table. The table is "Presentations" and column names are "TriageCategory" and "Isolation". I want to count all values in "Triage category" that = Life-Threatening and values in "isolation" that = yes. I can get the counts when I do separate queries for triage category and isolation, but the values are not correct when I put them in the same query. This is the SQL for the combined query:



    SELECT Presentations.triageCategory, Count(*) AS TotalLT, Presentations.isolation, Count(*) AS TotalIso
    FROM Presentations
    GROUP BY Presentations.triageCategory, Presentations.isolation
    HAVING (((Presentations.triageCategory)="Life-Threatening") AND ((Presentations.isolation)=True));

    Am I missing brackets somewhere that will ensure that the values are correct?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Off the top of my head:

    SELECT Sum(IIf(triageCategory="Life-Threatening", 1, 0)) As TotalLT, Sum(IIf(isolation=True, 1, 0)) As TotalIso
    FROM Presentations
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    kristaM79 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    2
    Quote Originally Posted by pbaldy View Post
    Off the top of my head:

    SELECT Sum(IIf(triageCategory="Life-Threatening", 1, 0)) As TotalLT, Sum(IIf(isolation=True, 1, 0)) As TotalIso
    FROM Presentations


    It worked!! Thank-you!!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 11-08-2017, 02:01 AM
  2. Replies: 0
    Last Post: 09-05-2017, 10:35 AM
  3. Replies: 0
    Last Post: 06-13-2016, 06:15 PM
  4. Replies: 1
    Last Post: 03-12-2013, 01:20 AM
  5. Replies: 2
    Last Post: 12-05-2011, 04:53 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