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



write sql query following table city gender no chennai male 40 chennai female 35 ..

Answer / chanakya

SELECT CITY,
SUM(DECODE(GENDER,'MALE',NO)) MALE ,
SUM(DECODE(GENDER,'FEMALE',NO)) FEMALE
FROM TABLE_NAME GROUP BY CITY

Is This Answer Correct ?    9 Yes 5 No

write sql query following table city gender no chennai male 40 chennai female 35 ..

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

write sql query following table city gender no chennai male 40 chennai female 35 ..

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

write sql query following table city gender no chennai male 40 chennai female 35 ..

Answer / anshita gupta

select * from city pivot(max(no) for gender in('male ','female'));

Is This Answer Correct ?    0 Yes 0 No

write sql query following table city gender no chennai male 40 chennai female 35 ..

Answer / venu

select* from tablename

Is This Answer Correct ?    1 Yes 5 No

Post New Answer

More Informatica Interview Questions

What is different between the data warehouse and data mart?

0 Answers  


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.

0 Answers   CTS,


What is mapplet in informatica?

0 Answers  


Which means the first record should come as last record and last record should come as first record and load into the target file?

0 Answers   Informatica,


How to join three sources using joiner? Explain though mapping flow.

0 Answers  






If we have lookup table in workflow how do you trouble shhot to increase performance?

2 Answers  


What is batch and describe about types of batches?

2 Answers  


Useful UNIX commands regular/frequently used

1 Answers   Deloitte,


how to join two flat file if they have diff. structure?how to join one relational and one flat file?

4 Answers   Wipro,


What is the difference between SOURCE and TARGET BASED COMMITS? What are the deliverables?in your project?

0 Answers   IBM,


Explain in detail scd type 2 through mapping.

0 Answers  


Can any one describe what is audit table briefly?how does it look like and what are the columns in it?

3 Answers   Syntel,


Categories