Results 1 to 6 of 6
  1. #1
    Fabdav is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    22

    Distinct count in a query

    I have a query I have 4 fields:
    E.G.
    Field1 Field2 Field3 Field4
    C 20 25 145541
    C 40 20 145541
    C 10 10 145540
    D 20 20 145540
    D 10 10 145538




    I need to obtain:

    C 70 55 2
    D 30 30 2


    I need to group Field1 and sum Field 3 and field3 and count the UNIQUE ID in field 4.

    Any suggestion?

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Do you mean:

    I need to obtain:

    C 70 55 3
    D 30 30 2

    ?

  3. #3
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Do you mean:

    I need to group Field1 and sum Field 3 and field4 and count the UNIQUE ID in field 4.



    I think you're on the right track.
    Group by 1, Sum 2 & 3 & Count 4.

  4. #4
    TinaCa is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    87
    Create the query as a select -make sure it runs - sounds like you got that far .

    Next select the totals button in the query creator (likes like a grate big E kind of). This will put the Total field in the grid of the query. In the first field select group from the drop down, then select sum for the second and third and count for the last one.

  5. #5
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    Group by 1, Sum 2 & 3 & Count 4

    It's not quite that easy. You're going to have to create a separate query to group by Field1 and Field4. Another query to group and sum Fields 1,2, & 3. Then a final query to join the first 2 queries on Field 1....group by Fields 1,2, & 3 and count field 4.

    You could probably write some sql and use subqueries, but I think the 3 separate queries is easier....although my description doesn't make it sound very easy!

  6. #6
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Congrats Kennejd;
    I have attached for OP to view and understand your explanation. Great solution as I was fumbling with this one for a good answer.

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

Similar Threads

  1. Count Distinct in Access
    By georgerudy in forum Access
    Replies: 1
    Last Post: 11-28-2010, 01:24 PM
  2. Access DB distinct count
    By anziga in forum Queries
    Replies: 3
    Last Post: 10-12-2010, 02:20 PM
  3. Count distinct records in parameterized query
    By SilverSN95 in forum Access
    Replies: 5
    Last Post: 07-27-2010, 09:31 AM
  4. Replies: 2
    Last Post: 11-18-2009, 06:49 PM
  5. Replies: 0
    Last Post: 08-08-2008, 08:34 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