Results 1 to 4 of 4
  1. #1
    Shilabrow is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    May 2014
    Posts
    34

    Group by Help and Count or Sum function

    I have a field Named Toys; Under Toys there are 5 kinds, Cars, Trucks Barbie, Piano, Bike. I want to Retrieve Toys but display only Car (Group Car, Truck and Bike - then count them), Piano and Barbie.



    I want to list only toys as CAR, Barbie, Piano. However I want the Car to include total count of cars, truck and bike AS CARS - pretty much rename the truck and bike as Cars and count them as CAR while counting the Piano and Barbie as well.

    All help in querying this will be appreciated. If I get the querying guideline to set the criteria that will be helpful.


    Thanks much!!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Create a Category field in query with expression and GROUP BY on that field. Is there a unique ID field?

    SELECT IIf([Toys]="Cars" Or [Toys]="Truck" Or [Toys]="Bike", "Vehicles", [Toys]) AS Category, Count([ID]) AS ToyCount FROM tablename GROUP BY IIf([Toys]="Cars" Or [Toys]="Truck" Or [Toys]="Bike", "Vehicles", [Toys]);
    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.

  3. #3
    Shilabrow is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    May 2014
    Posts
    34
    Thanks June,
    I don't know what am doing wrong but when I used a portion of the query to just retrieve the toys as CATEGORY IIf([Toys]="Cars" Or [Toys]="Truck" Or [Toys]="Bike", "Vehicles", [Toys]) AS Category from Table name. I get #Error in the field content and every other information I queried comes out from the table and the Toy field name properly changed name as CATEGORY just got error in the field content. This is without even doing the count. Note, I added more field queries but they all came out good except the CATEGORY field showing #Error.

    Please what am I doing wrong. Thanks much!!!!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Don't know. The query works with my test.

    Make sure the field names and the values are correctly spelled. Post your exact query statement.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

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

Similar Threads

  1. Replies: 4
    Last Post: 07-24-2013, 02:34 PM
  2. COUNT Group Count Records COUNT FUNCTION
    By PMCOFFEY in forum Access
    Replies: 9
    Last Post: 11-09-2012, 09:40 PM
  3. First Group, Second count, and third sum
    By hoachen in forum Access
    Replies: 2
    Last Post: 07-30-2012, 06:03 PM
  4. Replies: 0
    Last Post: 04-25-2011, 07:58 PM
  5. GROUP and COUNT?
    By TheMoodyFiles in forum Queries
    Replies: 2
    Last Post: 02-10-2011, 05:50 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