How to sort columns and rows in oracle

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahulae
    New Member
    • Jul 2008
    • 29

    How to sort columns and rows in oracle

    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
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    [code=oracle]

    SELECT SUM(CASE WHEN deptno = 10 THEN salary ELSE 0 END) dept_10,
    SUM(CASE WHEN deptno = 20 THEN salary ELSE 0 END) dept_20,
    SUM(CASE WHEN deptno = 30 THEN salary ELSE 0 END) dept_30
    FROM emp_details

    [/code]

    Comment

    • rahulae
      New Member
      • Jul 2008
      • 29

      #3
      case function does not work in oracle 8i,so can u please tell me how to use decode function.

      Comment

      • rahulae
        New Member
        • Jul 2008
        • 29

        #4
        thanx im able to do it using decode

        Comment

        Working...