Results 1 to 2 of 2
  1. #1
    Medee is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    1

    Count by Date, Month and Year in one Query

    Hi,
    I have a table that has a Date field. I need to generate a report for 24 hours, Month to date and Year to date. I have done individual group by queries to count by Date, Month to date and Year to date. The three queries are provided below. Is there a way that I can do this in one query? I have also attached the database that I have been using for this.

    Thanks.

    24 Hours Query
    Code:
    SELECT Table1.Service, Table1.Profile, Table1.dDate, Count(Table1.dDate) AS datecount
    FROM Table1
    GROUP BY Table1.Service, Table1.Profile, Table1.dDate
    HAVING (((Table1.dDate)=[varDate]));
    Month to Date Query


    Code:
    SELECT Table1.Service, Table1.Profile, Month([dDate]) AS mnthNumber, Count([mnthNumber]) AS mnthCount
    FROM Table1
    GROUP BY Table1.Service, Table1.Profile, Month([dDate])
    HAVING (((Month([dDate]))=[varMonth]));
    Year to Date Query
    Code:
    SELECT Table1.Service, Table1.Profile, Year([dDate]) AS yearNumber, Count([yearnumber]) AS countYear
    FROM Table1
    GROUP BY Table1.Service, Table1.Profile, Year([dDate])
    HAVING (((Year([dDate]))=[varYear]));
    Sample.accdb

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    if you mean one query to show all results, not as such. Use a UNION query to combine the three outputs but note you have two datatypes for column3 - a date and a number, these will need to go into different columns.

    You may also require an additional column to provide some sorting ability

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

Similar Threads

  1. Replies: 5
    Last Post: 08-14-2015, 02:53 PM
  2. Year Count and Month Count Same Query
    By NateSmith in forum Queries
    Replies: 1
    Last Post: 05-13-2015, 08:23 AM
  3. Replies: 5
    Last Post: 08-26-2014, 06:07 AM
  4. Replies: 8
    Last Post: 09-10-2013, 05:32 PM
  5. Replies: 4
    Last Post: 05-26-2013, 03:28 PM

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