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

  • Home
  • SEARCH
  • 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 6254859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:15:28+00:00 2026-05-24T14:15:28+00:00

how can I write a query to get total users, %female, %male from a

  • 0

how can I write a query to get total users, %female, %male from a user table. I have a user table having male and female column in it.

  • 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-24T14:15:29+00:00Added an answer on May 24, 2026 at 2:15 pm
    mysql> CREATE TABLE user ( username VARCHAR(20) NOT NULL, gender ENUM('male','female') );
    Query OK, 0 rows affected (0.09 sec)
    
    mysql> INSERT INTO user ( username, gender ) VALUES
        -> ( 'berry', 'male' ),
        -> ( 'jessica alba', 'female' ),
        -> ( 'Sasha DiGiulian', 'female' );
    Query OK, 3 rows affected (0.03 sec)
    Records: 3  Duplicates: 0  Warnings: 0
    
    mysql> SELECT COUNT(username), gender FROM user GROUP BY gender;
    +-----------------+--------+
    | COUNT(username) | gender |
    +-----------------+--------+
    |               1 | male   |
    |               2 | female |
    +-----------------+--------+
    2 rows in set (0.02 sec)
    
    
    mysql> SELECT total, gender, number, ( 100 * number / total ) AS percentage FROM ( SELECT COUNT(username) AS total FROM user ) AS total, ( SELECT COUNT(username) AS number, gender FROM user GROUP BY gender ) as genders;
    +-------+--------+--------+------------+
    | total | gender | number | percentage |
    +-------+--------+--------+------------+
    |     3 | male   |      1 |    33.3333 |
    |     3 | female |      2 |    66.6667 |
    +-------+--------+--------+------------+
    2 rows in set (0.00 sec)
    

    EDIT: Added calculation for percentages too.

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

Sidebar

Related Questions

HI, I have a large table from which i can query to get the
how can i write the query, to update the table videos , and set
How can I write a LINQ query that returns an hierachical anonymous type from
I'm writing a query to get fname from user_name_n column in following query I'm
In mysql I can write a query like Select a.field1 > a.field2 from a
In SQL one can write a query that searches for a name of a
How can I write a query similar to this one in LINQ to SQL
How can I write single UPDATE query to change value of COL1 to ‘X’
Using the C# compilers query comprehension features, you can write code like: var names
I am trying to write a query for SQL Server 2005 but I can't

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.