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 |
Types of cursors and explanation each of them ?
Is keyword pl sql?
What is the difference between UNIQUE CONSTRAINT and PRIMARY KEY? 1. There is no difference. 2. A PRIMARY KEY cannot be declared on multiple columns. 3. A UNIQUE CONSTRAINT cannot be declared on multiple columns. 4. A table can have multiple PRIMARY KEYS but only one UNIQUE CONSTRAINT. 5. A table can have multiple UNIQUE CONSTRAINTs but only one PRIMARY KEY.
What is coalesce sql?
What are the advantages of indexing?
What do we need to check in database testing?
How do I order columns in sql?
How to find 3rd highest salary of an employee from the employee table in sql?
What is record variable?
how to use regular expression in pattern match conditions? : Sql dba
what is inline command?
Does truncate remove indexes?