DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: how to write SQl query for the given problem below with a self join

Hybrid View

  1. #1
    Join Date
    Jul 2007
    Posts
    1

    how to write SQl query for the given problem below with a self join

    I was jus wondering how to write an sql query for retrieving the following
    data:

    Table columns... employee name, ID, employee grade, type of job pursuing.
    (The "type of job" field can take one out of 3 predefined values and is non

    null)- primary key of the table is employee ID

    Question: I want to know the no. of each type of job pursued by employees of
    each grade

    Output required... employee grade, No. of type 1 jobs pursued, no. of type 2

    jobs pursued, no. of type 3 jobs pursued.

    regds
    Raj

  2. #2
    Join Date
    Sep 2005
    Posts
    278
    Hope this will help you.

    Code:
    SELECT distinct grade,
            count(decode(job_type, 'Type1', 1))
                    over(partition by grade) t1,
            count(decode(job_type, 'Type2', 1))
                    over(partition by grade) t2,
            count(decode(job_type, 'Type3', 1))
                    over(partition by grade) t3
    FROM emp_grade
    ORDER BY 1
    Last edited by tabreaz; 07-26-2007 at 05:51 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width