Results 1 to 4 of 4
  1. #1
    BillR is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2016
    Posts
    2

    query with grouping and subqueries not working


    Imagine data from a camera looking at a highway, and when a vehicle goes by it records 2 fields: the datetime and whether the camera thinks it's a car, truck or something else, say "CAR", "TRK" or "OTH". What query would give me a date, the total number of vehicles and counts for each type for that date? I'm trying to get the subgroups using subqueries and can't get the syntax working. Thanks in advance.

  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,521
    Sounds like a totals query. Start a new query and add the date field and the type field twice. On the ribbon, click on the Totals icon, looks like an "E". Change the Group By to Count for one of the type fields. Oh, and wrap the date/time field in the DateValue() function to return just the date.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    With that, I think you'll only get a count of the types by date, not a count of the total for a date. The type will break it out into groups but I think the OP wants a total count by date. You should be able to get the counts of type for a date using a Totals query as suggested. Then add that query to a second, joined to the table by date and count the date. Such as
    Code:
    SELECT tblAutoTypes.TheDate, tblAutoTypes.TheType, Count(tblAutoTypes.TheType) AS CountOfTheType
    FROM tblAutoTypes
    GROUP BY tblAutoTypes.TheDate, tblAutoTypes.TheType;
    Code:
    SELECT Query16.TheDate, Query16.TheType, Query16.CountOfTheType, Count(tblAutoTypes.TheDate) AS CountOfTheDate
    FROM Query16 INNER JOIN tblAutoTypes ON Query16.TheDate = tblAutoTypes.TheDate
    GROUP BY Query16.TheDate, Query16.TheType, Query16.CountOfTheType;
    The first query is just named Query16.
    Last edited by Micron; 03-01-2017 at 02:24 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    BillR is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2016
    Posts
    2
    Thanks! I'll give them a try.

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

Similar Threads

  1. Replies: 6
    Last Post: 09-09-2015, 10:14 AM
  2. Subqueries with more results
    By reentry in forum Queries
    Replies: 7
    Last Post: 02-25-2015, 01:17 PM
  3. Summing 2 subqueries
    By bd528 in forum Access
    Replies: 8
    Last Post: 09-27-2012, 02:22 PM
  4. Structuring Subqueries
    By dandoescode in forum Queries
    Replies: 1
    Last Post: 03-13-2012, 06:42 PM
  5. Grouping not working
    By jgelpi16 in forum Reports
    Replies: 3
    Last Post: 08-24-2010, 11:50 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