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

Why stored procedure is better than query?

0 Answers  


What are tables in sql?

0 Answers  


What are the two characteristics of a primary key?

0 Answers  


how to concatenate two character strings? : Sql dba

0 Answers  


Does truncate free space?

0 Answers  






what are the differences between procedure-oriented languages and object-oriented languages? : Sql dba

0 Answers  


what is the bond code in materialized view?

0 Answers  


What is having clause in sql?

0 Answers  


How do I view stored procedures?

0 Answers  


What is mutating trigger?How to avoid it??

3 Answers   Tech Mahindra,


Explain the steps needed to create the scheduled job?

0 Answers  


What is a null value?

0 Answers  


Categories