Question: Below is the table

city gender name
delhi male a
delhi female b
mumbai male c
mumbai female d
delhi male e

I want the o/p as follows:

male female
delhi 2 1
mumbai 1 1

Please help me in writing the query that can yield the o/p
mentioned above?

Answers were Sorted based on User's Feedback



Question: Below is the table city gender name delhi male ..

Answer / kavitha nedigunta

select city,
count(decode(lower(gender),'male','female',null)) male,
count(decode(lower(gender),'female','male',null)) female
from gen
group by city;

Is This Answer Correct ?    8 Yes 2 No

Question: Below is the table city gender name delhi male ..

Answer / sp

SELECT
city, COUNT(
CASE gender
WHEN 'male' THEN 'male'
END ) AS 'male' ,COUNT(
CASE gender
WHEN 'female' THEN 'female'
END ) AS 'female'
FROM info AS u group by city;

Is This Answer Correct ?    4 Yes 0 No

Post New Answer

More SQL PLSQL Interview Questions

Types of cursors and explanation each of them ?

4 Answers   DELL,


Is keyword pl sql?

0 Answers  


What is the difference between UNIQUE CONSTRAINT and PRIMARY KEY? 1. There is no difference. 2. A PRIMARY KEY cannot be declared on multiple columns. 3. A UNIQUE CONSTRAINT cannot be declared on multiple columns. 4. A table can have multiple PRIMARY KEYS but only one UNIQUE CONSTRAINT. 5. A table can have multiple UNIQUE CONSTRAINTs but only one PRIMARY KEY.

7 Answers   Satyam,


What is coalesce sql?

0 Answers  


What are the advantages of indexing?

0 Answers  






What do we need to check in database testing?

0 Answers  


How do I order columns in sql?

0 Answers  


How to find 3rd highest salary of an employee from the employee table in sql?

0 Answers  


What is record variable?

0 Answers  


how to use regular expression in pattern match conditions? : Sql dba

0 Answers  


what is inline command?

2 Answers  


Does truncate remove indexes?

0 Answers  


Categories