Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 does over partition by mean in sql?

1048


What are sql commands?

1067


how to convert character strings to numeric values? : Sql dba

1170


How many parts of a pl sql block are optional?

1222


What is vector point function?

1098


What is a sql trace file?

1085


Which is faster view or stored procedure?

1012


Does truncate release storage space?

1142


What are the different dml commands in sql?

1249


Explain about various levels of constraint.

1000


Define tables and fields in a database

1182


What are the operators in sql?

1073


What are properties of the transaction?

1049


Why do we go for stored procedures?

1128


Can you have a foreign key without a primary key?

1001