Results 1 to 5 of 5
  1. #1
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83

    Count on ID

    I have a large table with Month and Identification. I need to create a query that shows only Identification numbers that are in every since month (i have 4 months loaded). E.g. ID number 5 is in jan, feb, mar, apr. and ID number 6 is in jan, feb, mar, but only 5 would be returned in the query and the count (so if it occurred 10 times over those 4 months the query would ready ID 5 | COUNT 10). There are about 150000 records since the month and ID have very detailed fields in their records. The primary key is an AutoNumber field. Something like this may work, but I am stumped?

    Code:
    SELECT ID, MONTH, [Whatever else]
    FROM IdsAll
    WHERE ....
    Or do i create a table for each month and setup a query that way? Thanks in advanced.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Can you give an example of what your data looks like in the table and what you want it to look like in your query because I'm a little confused by your descriptions.

  3. #3
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83
    This is the table

    AutoNumber | Report Month | ID | Location | Revenue | Discounts | Entry No. | Date Received | Name | Acct No | .... the many more fields are currency fields

    This would be the query

    Code:
    SELECT ID, Count(ID) as CountofID, Name, ...whatever else
    FROM tblIdAll INNER JOIN tblId ON tblIdAll.[Ids] = tblId.[Ids]
    WHERE ... (get only IDs in all months);

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Ok that's your table structure, but what does your data look like and what do you want it to look like?

  5. #5
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83
    I was able to create a solution. Sorry for being unclear but I was unable to share the data, so it was hard to explain what I was working with. This is what I did:


    Code:
    'Create a subquery that does a count distinct with ID and month. 
    'The total sum per ID should be 1,2,3 or 4 depending on its unique occurrence
    in either of the four months. This will tell me if an ID is in all four months at least once 
    (so i put a condition in this subquery for 4).
    This acts as the "primary key query" for the master table to get 
    only those IDs 'and all the detail i need with it
    
    SELECT P.[ID], tblMaster.[Detail Field here], tblMaster.[Detail Field here], tblMaster.Detail Field here, tblMaster.Detail Field here
    FROM (SELECT Count(*) AS N, T.[ID]
    FROM (SELECT DISTINCT [Month], [ID] FROM tblMaster)  AS T
    GROUP BY T.[Patient Number]
    HAVING (((Count(*))=4))
    )  AS P INNER JOIN tblMaster ON P.[ID] = tblMaster.[ID]

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

Similar Threads

  1. Sum the Count
    By Adele in forum Queries
    Replies: 5
    Last Post: 07-26-2011, 06:16 AM
  2. Count is off when using =Count
    By boywonder in forum Programming
    Replies: 3
    Last Post: 06-09-2011, 12:14 PM
  3. How to count characters?
    By Jorge Junior in forum Access
    Replies: 1
    Last Post: 05-22-2011, 08:07 PM
  4. SQL Count and Group By
    By Tyork in forum Programming
    Replies: 11
    Last Post: 01-24-2011, 09:06 AM
  5. Using count or Dcount
    By ddcook in forum Access
    Replies: 0
    Last Post: 07-22-2009, 03:35 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