GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Oracle  >  General

 Print  |  
Question:   dear friend

i want to know that in a table how to change the column to row.





December 12, 2006 06:01:54 #3
 rampratap409   Member Since: September 2006    Total Comments: 108 

RE: dear friendi want to know that in a t...
 

select deptno, count(*) no_emp from emp group by deptno;

    this will give you like

deptno          no_emp

10                  4

20                   5

...........

now to put this result in a single row use:

select count(decode(deptno,10, deptno, null)) No_empof_10dept,

count(decode(deptno,20,deptno,null)) no_empof_20dept,

count(decode(deptno,10,null, 20 , null, deptno)) otherthen_10_20

from emp;

     

 

Back To Question