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?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Is foreign key mandatory?

716


What is the difference between inner join and natural join?

711


What are secondary keys?

737


Why do we need unique key in a table?

673


Is there a pl/sql pragma similar to deterministic, but for the scope of one single sql select?

759






Which is better join or subquery?

793


What is snowflake sql?

800


What are different types of sql?

757


How do I debug a stored procedure?

813


Does db2 use sql?

673


How to select the Nth maximum salary from Table Emp in Oracle SQL Plus ?

814


What does := mean in pl sql?

757


What is a procedure in pl sql?

783


What is difference between sql and oracle?

778


Can we use join in subquery?

781