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
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 |
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 |
Explain what is sql?
What is cursor status?
What is integrity constraints?
What is the difference between sql, mysql and sql server?
What are the possible values for the boolean data field?
What is the difference between union and union all command?
if a table is getting updated what happens if a function is called from sql query?
What is Collation Sensitivity ? What are the various type ?
Authentication mechanisms in Sql Server ?
What are the advantages of sql?
What is difference between stored function and application function?
how to convert numeric values to character strings? : Sql dba
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)