Table contain 2 columns like name and genderfor that i need output like this..countof female countofmale totalcountforeg 5 3 8

Showing Answers 1 - 2 of 2 Answers

Sandeep Sharma

  • Oct 24th, 2006
 

  1. Select Male,Female,Other,(Male+Female+Other) total from
  2. ( select count(*) Male from voters where gender = 1 ) A,
  3. ( select count(*) Female from voters where gender = 0 ) B,
  4. ( select count(*) Other from voters where gender is null ) C ;

  Was this answer useful?  Yes

sanju699369

  • Oct 24th, 2006
 

Select Male,Female,Other,(Male+Female+Other) total from

( select count(*) Male from voters where gender = 1 ) A,

( select count(*) Female from voters where gender = 0 ) B,

( select count(*) Other from voters where gender is null ) C

  Was this answer useful?  Yes

vkc_keerthi

  • Apr 14th, 2010
 


select
count( case when gender='M' then 1 end) "Male_count" ,
count(case when gender='F' then 1 end) Female_count,
count(*) Total_count from
temp1

  Was this answer useful?  Yes

neelapu

  • Apr 16th, 2010
 

SELECT COUNT(decode(gender,'M',1,0)) "count of male",

COUNT(decode(gender,'F',1,0)) "count of Female",
COUNT(*) "Total Count"
FROM <table name>
GROUP BY gender;

  Was this answer useful?  Yes

PK

  • Feb 29th, 2012
 

There is one Oracle function ROLLUP, the same can be used for required output

QUERY:
SELECT GENDER,COUNT(GENDER)
FROM TABLE_NAME GROUP BY ROLLUP(GENDER);

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions