Results 1 to 4 of 4
  1. #1
    CJFugate is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Jul 2017
    Posts
    3

    Counting all occurrences of a unique value


    All -

    I'm trying to make a query that will count how many lengths are with each project (see attached image). Basically, each project is unique and there are multiple lengths associated with that project. I'd like a query that gives me the count of lengths for each project. I suck at SQL but am slooowlllyy learning.Click image for larger version. 

Name:	project count.png 
Views:	17 
Size:	27.2 KB 
ID:	38022

    Thanks!

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Create a select query and add both fields. Now click the Totals button in the ribbon to change it to an aggregate query.
    The totals row in the query will say Group By for each field
    Change that to Count for the Length field
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Since lengths are repeated within project and you want to count how many unique lengths associated with project, that requires two aggregate queries - which can be nested.

    SELECT Project, Count(*) AS CountLength FROM (SELECT DISTINCT Project, Length FROM table) AS Q1 GROUP BY Project;
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Or if you want the count for each project and length value then:
    Code:
    SELECT Project, Length, Count(Length) AS CountOfLength
    FROM YourTableName
    GROUP BY Project, Length;
    For info my original suggestion was:
    Code:
    SELECT Project, Count(Length) AS CountOfLength
    FROM YourTableName
    GROUP BY Project;
    One of the 3 solutions provided should hopefully suit your needs
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Counting occurrences using a query
    By RickK in forum Queries
    Replies: 4
    Last Post: 11-16-2016, 09:31 AM
  2. Counting occurrences of specific data
    By DaveC in forum Reports
    Replies: 1
    Last Post: 09-12-2016, 01:29 PM
  3. Replies: 22
    Last Post: 11-28-2015, 06:14 PM
  4. Replies: 5
    Last Post: 03-17-2014, 04:02 PM
  5. counting unique entries
    By Pastor Del in forum Queries
    Replies: 3
    Last Post: 01-12-2014, 02:55 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