table having two columns - entity,zone
enity zone
pen east
pen west
pen north
pen south
pen east
pencil east
pencil east
pencil west

I want the output as :
entity east west north south
pen 2 1 1 1
pencil 2 1 0 0

Answer Posted / aswini mohanty

select entity,sum(decode(zone,'east',1,0)) east,
sum(decode(zone,'west',1,0)) west,
sum(decode(zone,'north',1,0))north,
sum(decode(zone,'south',1,0))south
from t group by entity;

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is join an inner join?

536


How to avoid duplicate records in a query?

579


What plvcmt and plvrb does in pl/sql?

879


What are the three forms of normalization?

525


what are the 'mysql' command line options? : Sql dba

554






what is oltp (online transaction processing)? : Sql dba

532


What is trigger and how to use it in sql?

540


what is auto increment? : Sql dba

573


What is structural independence and why is it important?

550


Is oracel sql developer written in java?

648


what is sql? : Sql dba

557


What is sql basics?

580


Which normal form is best?

515


Why having clause is used in sql?

540


How do you update a sql procedure?

525