Results 1 to 5 of 5
  1. #1
    dfenton21 is offline Novice
    Windows XP Access 97
    Join Date
    May 2011
    Posts
    6

    Count Problem

    I have the following query:



    SELECT
    Sessions.SessionID,
    Sessions.SessionType,
    Sessions.SessionDate,
    Count(Bookings.Status) AS BookedPlaces
    FROM Sessions
    LEFT JOIN Bookings ON Sessions.SessionID = Bookings.SessionID
    GROUP BY
    Sessions.SessionID,
    Sessions.SessionType,
    Sessions.SessionDate,

    That works perfectly for me. I have four records in the Sessions table. The query gives me the four records and the number of booked places per session (as listed in the Bookings table)

    However, I need to change
    Count(Bookings.Status) AS BookedPlaces
    to count only when Bookings.Status='Active'.

    Everything I've tried only counts all the records and not grouped by SessionID, or gives me a syntax error, or says that "at most, one record can be returned from this subquery.

    I would appreciate if someone could assist me with this as I've spend the last 1.5 hours trying to figure it out (I have an inkling that the solution is very simple which makes it more frustrating)

    Thanks.

  2. #2
    jeffr27 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    May 2011
    Posts
    3
    I'm not an expert by any means, but could you possibly do something like:

    SELECT...fields
    Count(Bookings.Status) AS BookedPlaces
    WHERE Bookings.Status=Active
    FROM...
    LEFTJOIN...

  3. #3
    dfenton21 is offline Novice
    Windows XP Access 97
    Join Date
    May 2011
    Posts
    6
    Thanks for your reply.

    I tried that already and it gives me a syntax error (missing operator)

  4. #4
    jeffr27 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    May 2011
    Posts
    3
    Is Bookings.Status a yes/no field? If so, try using =yes or true or 1 instead of 'Active'.

  5. #5
    dfenton21 is offline Novice
    Windows XP Access 97
    Join Date
    May 2011
    Posts
    6
    No, the Status field can contain three possibilities.

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

Similar Threads

  1. GROUP and COUNT?
    By TheMoodyFiles in forum Queries
    Replies: 2
    Last Post: 02-10-2011, 05:50 PM
  2. Count Records
    By Cheshire101 in forum Access
    Replies: 1
    Last Post: 11-30-2010, 03:02 PM
  3. Performing count in VBA
    By jgelpi16 in forum Programming
    Replies: 3
    Last Post: 08-21-2010, 07:41 PM
  4. Replies: 2
    Last Post: 06-14-2010, 03:25 PM
  5. Count of records
    By Aston in forum Access
    Replies: 2
    Last Post: 03-30-2010, 05:20 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