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

What is sp_helptext?

684


what are the differences between public, private, protected, static, transient, final and volatile? : Sql dba

633


Does truncate remove indexes?

639


What is difference between function and trigger?

632


what is bcp? When does it used? : Sql dba

608






How do you copy a table in sql?

658


What is the maximum number of triggers, you can apply on a single table?

644


Explain the purpose of %type and %rowtype data types?

591


What is union, minus and interact commands?

849


Is it possible to pass parameters to triggers?

664


What is type and rowtype in pl sql?

636


Is sql dba a good career? : SQL DBA

624


How are sql commands classified?

682


Define the select into statement.

673


What are the different types of tables in sql?

571