write sql query following table
city gender no
chennai male 40
chennai female 35
bangalore male 25
bangalore female 25
mumbai female 15
i want the required output
city male female
chennai 40 35
bangalore 25 25
mumbai 15
Answers were Sorted based on User's Feedback
Answer / venky
select city,sum(c1) male,sum(c2) female from(select
city,decode(gender,'male',no,0)
c1,decode(gender,'female',no,0) c2 from tablename) tablename
group by city;
Is This Answer Correct ? | 4 Yes | 3 No |
Answer / sudheer
Select ABC.CITY AS CITY, sum(ABC.male) as MALE, sum(ABC.Female) as FEMALE from
(
select city, Sum(no) as male, NULL AS female from table_name
where gender = 'male'
Group by city
UNION
select city, NULL as male, SUM(no) AS female from table_name
where gender = 'female'
Group by city
) ABC Group by CITY
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / anshita gupta
select * from city pivot(max(no) for gender in('male ','female'));
Is This Answer Correct ? | 0 Yes | 0 No |
What is different between the data warehouse and data mart?
I have 10 columns in a flat file and 10 rows corresponding to that columns. I want column number 5 and 6 for last five records. In unix as well as informtica.
What is mapplet in informatica?
Which means the first record should come as last record and last record should come as first record and load into the target file?
How to join three sources using joiner? Explain though mapping flow.
If we have lookup table in workflow how do you trouble shhot to increase performance?
What is batch and describe about types of batches?
Useful UNIX commands regular/frequently used
how to join two flat file if they have diff. structure?how to join one relational and one flat file?
What is the difference between SOURCE and TARGET BASED COMMITS? What are the deliverables?in your project?
Explain in detail scd type 2 through mapping.
Can any one describe what is audit table briefly?how does it look like and what are the columns in it?