Connecting Tech Pros Worldwide Forums | Help | Site Map

How to sort columns and rows in oracle

Newbie
 
Join Date: Jul 2008
Posts: 29
#1: Sep 11 '08
The output that i'm getting is

deptno sum(sal)
10 8750
20 10875
30 9400

when i execute the query select deptno,sum(sal) from emp group by deptno;

I should get the total sal of each dept in such a way that output should be like this
which is below

Output:

10 20 30
8750 10875 9400

amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#2: Sep 11 '08

re: How to sort columns and rows in oracle


Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT SUM(CASE WHEN deptno = 10 THEN salary ELSE 0 END) dept_10,
  3. SUM(CASE WHEN deptno = 20 THEN salary ELSE 0 END) dept_20,
  4. SUM(CASE WHEN deptno = 30 THEN salary ELSE 0 END) dept_30
  5. FROM emp_details
  6.  
  7.  
Newbie
 
Join Date: Jul 2008
Posts: 29
#3: Sep 11 '08

re: How to sort columns and rows in oracle


case function does not work in oracle 8i,so can u please tell me how to use decode function.
Newbie
 
Join Date: Jul 2008
Posts: 29
#4: Sep 11 '08

re: How to sort columns and rows in oracle


thanx im able to do it using decode
Reply