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
What does over partition by mean in sql?
What are sql commands?
how to convert character strings to numeric values? : Sql dba
How many parts of a pl sql block are optional?
What is vector point function?
What is a sql trace file?
Which is faster view or stored procedure?
Does truncate release storage space?
What are the different dml commands in sql?
Explain about various levels of constraint.
Define tables and fields in a database
What are the operators in sql?
What are properties of the transaction?
Why do we go for stored procedures?
Can you have a foreign key without a primary key?