Results 1 to 6 of 6
  1. #1
    bas85 is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2012
    Posts
    4

    Group by two columns and count

    I am trying to do this:

    SELECT DISTINCT COMBINED.[Class], COMBINED.[Class Scheme], COUNT(*)
    FROM COMBINED
    WHERE (((cost])="0"));

    but it does not work.

    I would like to groupy by the first two columns and count them but it does not work and I am having trouble. Please any help would be great!!!

    I am trying to do exactly this in Access. This is the example I am trying to follow:

    SELECT species, sex, COUNT(*) FROM Bird GROUP BY species, sex;


    +---------+------+----------+
    | species | sex | COUNT(*) |
    +---------+------+----------+
    | Bus | m | 2 |
    | Car | f | 1 |
    +---------+------+----------+
    2 rows in set (0.02 sec)


  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,530
    You left out the GROUP BY clause from the example. It would go after the WHERE clause.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    bas85 is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2012
    Posts
    4
    Sorry this is the query I am running and it still doesn't work.

    SELECT DISTINCT COMBINED.[Class], COMBINED.[Class Scheme], Count(*)
    FROM COMBINED
    GROUP BY COMBINED.[Construction Class], COMBINED.[Construction Class Scheme]
    HAVING ((((COMBINED.[Cost]))="0"));

  4. #4
    bas85 is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2012
    Posts
    4
    SELECT DISTINCT COMBINED.[Class], COMBINED.[Class Scheme], Count(*)
    FROM COMBINED
    GROUP BY COMBINED.[Class], COMBINED.[Class Scheme]
    HAVING ((((COMBINED.[Cost]))="0"));

  5. #5
    bas85 is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2012
    Posts
    4
    I got it to work!!

    SELECT DISTINCT COMBINED.[Class], COMBINED.[Class Scheme], Count(COMBINED.[Cost]) AS [CountOfCost]
    FROM COMBINED
    Where ((((COMBINED.[Cost]))="0"))
    GROUP BY COMBINED.[Class], COMBINED.[Class Scheme];

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Good job, and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. First Group, Second count, and third sum
    By hoachen in forum Access
    Replies: 2
    Last Post: 07-30-2012, 06:03 PM
  2. Replies: 3
    Last Post: 04-19-2012, 01:22 PM
  3. GROUP and COUNT?
    By TheMoodyFiles in forum Queries
    Replies: 2
    Last Post: 02-10-2011, 05:50 PM
  4. SQL Count and Group By
    By Tyork in forum Programming
    Replies: 11
    Last Post: 01-24-2011, 09:06 AM
  5. columns for group detail but not group header?
    By Coolpapabell in forum Reports
    Replies: 0
    Last Post: 08-21-2009, 08:53 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