Results 1 to 4 of 4
  1. #1
    Dinky is offline Novice
    Windows 7 Access 2007
    Join Date
    Dec 2010
    Posts
    2

    Calculating percentage from two different queries

    Hi guys, I'm new to this forum, and in some serious need of help with a newbie assignment.

    I have a database of dogs in a kennel, and I'm asked to create a query that lists how many dogs there are of each gender in the kennel. I think I've got an okay solution for this, the SQL-code is as follows:



    SELECT Count(tblDog.DogNr) AS CountOfDogNr, tblDog.Gender
    FROM tblDog
    GROUP BY tblDog.Gender

    I'm then asked to give a selection that shows how many dogs weigh above 10 kg, which I've also done, though I'm not sure if this is the best way to do it:

    SELECT Count(tblDog.DogNr) AS CountOfDogNr, tblDog.Gender
    FROM tblDog
    WHERE (((tblDog.Weigth)>=10))
    GROUP BY tblDog.Gender;


    But I'm stuck on the next task, which is to provide a percentage of the number of dogs that weighs more than 10 kg. I guess I have to make a new query which calculates the percentage by dividing the count of dogs above 10 kg with the total count of dogs, sorted by gender (and then formatting the field to show percentage). But I'm not sure how to do this, and I can't get it right. I'm wondering if I'm doing something wrong in the two first queries.

    Any help would be greatly appreciated!

    I'm using Access 2007, by the way.

  2. #2
    ConneXionLost's Avatar
    ConneXionLost is offline Simulacrum
    Windows XP Access 2003
    Join Date
    Jan 2010
    Location
    Victoria, Canada
    Posts
    291
    First, add titles to your existing queries.

    queryA: qryCountDogsByGender; and,
    queryB: qryCountLargeDogsByGender

    Second, make a small adjustment to your queryB:

    Code:
    SELECT Count(tblDog.DogNr) AS CountOfLargeDogNr, tblDog.Gender
    FROM tblDog
    WHERE (((tblDog.Weight)>=10))
    GROUP BY tblDog.Gender;
    Third, build a new query that uses the first two to answer your question:

    Code:
    SELECT [CountOfLargeDogNr]/[CountOfDogNr] AS LargeDogPercent, qryCountDogsByGender.Gender
    FROM qryCountDogsByGender INNER JOIN qryCountLargeDogsByGender ON qryCountDogsByGender.Gender = qryCountLargeDogsByGender.Gender;
    Finally, format LargeDogPercent as percent.

    Cheers,

  3. #3
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    See if this works for you.

    SELECT Gender, Format(DLookUp("DogNr","tblDog","weight >=10")/Count([DogNr), "Percent") AS Percent
    FROM tblDog
    GROUP BY Gender;

  4. #4
    Dinky is offline Novice
    Windows 7 Access 2007
    Join Date
    Dec 2010
    Posts
    2
    You have my greatest thanks ConneXion, that solved it for me.

    Thank you both for your time.

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

Similar Threads

  1. Add fields and find percentage
    By gurp99 in forum Queries
    Replies: 1
    Last Post: 08-09-2010, 03:57 PM
  2. Percentage Calculation in a Query
    By Lynn in forum Queries
    Replies: 1
    Last Post: 07-16-2010, 11:23 PM
  3. Use report to Calculate sum and percentage
    By bangemd in forum Reports
    Replies: 3
    Last Post: 05-28-2009, 12:01 PM
  4. Percentage Queries
    By bangemd in forum Queries
    Replies: 18
    Last Post: 05-21-2009, 09:32 AM
  5. percentage in a query
    By Peljo in forum Access
    Replies: 2
    Last Post: 02-27-2008, 10:51 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