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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:44:13+00:00 2026-06-11T02:44:13+00:00

In my database table I have two columns that hold either 0 or 1.

  • 0

In my database table I have two columns that hold either 0 or 1.

I have type and Gender, where type means 0 => teacher and 1 => student and for gender: 0 => male and 1 => female.

How can I write a single sql query to get number of teachers, students, males and females?

Right now I have:

select COUNT(type) as teachers from my_table where type = 0; // Teachers
select COUNT(type) as students from my_table where type = 1; // Students
select COUNT(gender) as males from my_table where type = 0; // Males
select COUNT(gender) as females from my_table where type = 1; // Females

Can it be done in one query? If so, how?

  • 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-11T02:44:15+00:00Added an answer on June 11, 2026 at 2:44 am

    This way you can do it in a single query. If you have only two types of data in your table then you don’t need to specify IN conditions in WHERE clause:

    SELECT SUM(IF(type = 1, 1, 0)) as students,
           SUM(IF(type = 0, 1, 0)) as teachers,
           SUM(IF(gender = 1, 1, 0)) as females,
           SUM(IF(gender = 0, 1, 0)) as males
    FROM my_table
    WHERE type IN(0,1)
          AND gender IN(0,1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Should a database table that contains two columns that are foreign keys have a
I have a database table called users This table has two columns (that are
In my database have one table AM_HISTORY in that two columns like USER_ID ,
I have a MySQL database table with two columns that interest me. Individually they
I have two columns(column1, column2) in my oracle database table named as demo .
Lets say we have a database table with two columns, entry_time and value. entry_time
I have a very simple database table that joins two other tables in a
I have two columns (among others) in a database table: ExitDate and ExitReason. Our
In a database i have a table prospect and has two columns firstname and
Okay, so let's say I have a mysql database table with two columns, one

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.