Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6391485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:40:38+00:00 2026-05-25T03:40:38+00:00

have two three tables one for student, second for class, and the third for

  • 0

have two three tables one for student, second for class, and the third for gender. I am trying to get the total number of each gender and the percentage. I used the following statment to get the number and it works well:

SELECT Gender.GenderName as Gender, COUNT(*) as cnt  
FROM         (Client INNER JOIN
             Gender ON Student.GenderID = Gender.GenderID)
             GROUP BY Gender.GenderName

I could not figure out how I can get the percenage, also how to make ClassName or ID as as selectable item to get the gender for each class or all classes by using @ClassId int.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:40:39+00:00Added an answer on May 25, 2026 at 3:40 am

    I don’t have access to a SQL Server right now but you use either Cast or Convert to convert to a floating type. Or you may want to refer to your SQL Server’s documentation for its specific type conversion functions.

    SELECT a.Gender, a.cnt, Cast(a.cnt as float) / b.cnt * 100
      FROM (SELECT Gender.GenderName as Gender, COUNT(*) as cnt
              FROM Client 
        INNER JOIN Gender 
               ON Student.GenderID = Gender.GenderID 
          GROUP BY Gender.GenderName) a
        CROSS JOIN (SELECT COUNT(*) as cnt FROM student) b
    

    PS: Thanks for pointing out my mistake. a.cnt/b.cnt would do integer math and return zero if b.cnt > a.cnt (In this case it would be) … we need to convert either a.cnt or b.cnt to a float so a.cnt/b.cnt becomes a float and then times it by 100 to give you the percent. Also, I missed that the GenderName had been aliased in the inner SELECT.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables one has a three column composite key. The other needs
I have two tables, say teacher and student. I want to build a third
I have three tables in which two are master tables and other one is
I have two tables, each with three boolean (ms-access Yes/No) columns. Table 1: A1,
I have two product tables Product1 and Product2. There is a one 2 one
I have two String arrays a,b. String a [] = {one,two,three}; String b []
I have two tables. In the one table I have a list of dorm
I have three tables. Two use a foreign key that pulls in data and
I have three tables, one of users, one of cases, and one with links
I have two tables like the below one in my DB. In the first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.