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 |
Is sql a case sensitive language?
What does cursor do in sql?
What is tuple in sql?
how are mysql timestamps seen to a user? : Sql dba
What will be the output of this Query? select to_char(trunc(add_months(sysdate-3),mm),mm/dd/yyyy) from dual
Are ddl triggers fired for ddl statements within a pl/sql code executed using the dbms.sql package?
Which join is like inner join?
Can i use Commit inside the Trigger? Suppose i use commit what will be happy (it's complied /executed/work)
can we call a procedure from a function?
What are the two parts of a procedure ?
What is a schema in sql?
What is mutating sql table?
Oracle (3253)
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)