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

what are the differences between binary and varbinary? : Sql dba

535


What is restrict in sql?

561


What is the maximum number of columns in sql table?

551


What are the advantages of pl sql?

607


How can you get sql*loader to commit only at the end of the load file? : aql loader

556






How many types of triggers are there in pl sql?

574


Which one is faster ienumerable or iqueryable?

487


How do you update f as m and m as f from the below table testtable?

1089


Is trigger a stored procedure?

509


What do you understand by case manipulation functions?

547


What is left join in sql?

585


does sql support programming? : Sql dba

611


What is the command used to fetch the first 5 characters of a string?

710


What are sql constraints?

566


What are sql ddl commands?

552