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 8387971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:21:43+00:00 2026-06-09T18:21:43+00:00

I wanted to a count of the same field for different values for example:

  • 0

I wanted to a count of the same field for different values for example:

user{user_id, gender}

Gender can have obviously male or female 🙂

i want to get count for all the males and females i.e.

COUNT(male)   COUNT(female)  
   4               16

but im confused because they come from the same gender coloumn thanks

  • 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-06-09T18:21:45+00:00Added an answer on June 9, 2026 at 6:21 pm

    Try this for row wise result:

    SELECT gender, COUNT(User_id) AS count
    FROM User
    GROUP BY gender;
    

    Output:

    | gender | count |
    |--------|-------|
    |      F |     4 |
    |      M |     2 |
    

    Try this for row wise result with grand total:

    SELECT  (IFNull(gender,'Total')) AS gender,
    COUNT(User_id) AS Count
    FROM User
    GROUP BY gender
    WITH rollup;
    

    Output:

    | gender | Count |
    |--------|-------|
    |      F |     4 |
    |      M |     2 |
    |  Total |     6 |
    

    Try this for column wise result:

    SELECT
      COUNT(CASE WHEN gender = 'M' THEN User_id END) AS males,
      COUNT(CASE WHEN gender = 'F' THEN User_id END) AS females,
      COUNT(*) AS Total
    FROM User;
    

    Output:

    | males | females | Total |
    |-------|---------|-------|
    |     2 |       4 |     6 |
    

    See this SQL Fiddle

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

Sidebar

Related Questions

I have multiple linq queries that retrieve the same data just at different grouping
I wanted to count number of characters in a string which I pull from
I wanted to write a regex to count the number of spaces/tabs/newline in a
I'm working in NetBeans. I wanted to make a simple 3-2-1 count down after
I wanted to create smth similar to this one Kansas county map where user
I have been learning about indexes in Oracle SQL, and I wanted to conduct
Can the same mysql resource be used for multiple queries? $queries=array($q1, $q2); $link=mysql_connect(...); mysql_select_db(...);
I have a dictionary of objects, all of different types but derived from the
I wanted to know: Does hadoop mapreduce re-process the entire dataset if the same
I'm not sure if this can be done. But I just wanted to check

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.