Results 1 to 5 of 5

Thread: To find ratio !!!

  1. #1
    Contributing Member
    Join Date
    May 2008
    Answers
    39

    Smile To find ratio !!!

    Hi, i have the following tables... Employee, manager, dept & payscale.

    I need to find the ratio of manager and employees salary. I found out managers' and employees' salary individually.....
    Select sum(p.basicsal) manager_sal from employee e, manager m, payscale p where e.empid = m.empid and p.empid = e.empid;

    select sum(p.basicsal) employee_sal from employee e, manager m, payscale p where e.empid != m.empid and p.empid = e.empid;

    i need to join above two queries and have to find out the ratio... Can any one help me out....?


  2. #2
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: To find ratio !!!

    Try this query

    Code:
    SELECT a.empid,
           nvl(b.mgrid,0), 
    	   a.empsal,
    	   b.mgrsal, 
    	   nvl(b.mgrsal,0)/a.empsal as ratio
    FROM
    (
        SELECT   e.empid, 
    	     sum(p.basicsal) empsal 
        FROM     employee e,Payscale p
        WHERE    e.empid = p.empid
        GROUP BY e.empid
    )a LEFT OUTER JOIN
    (
       SELECT   m.mgrid,
       	    m.empid,
    	    sum(p.basicsal) mgrsal
       FROM     manager m, payscale p
       WHERE    m.mgrid = p.empid
       GROUP BY m.mgrid,m.empid
    )b
    ON a.empid = b.empid



  3. #3
    Contributing Member
    Join Date
    May 2008
    Answers
    39

    Re: To find ratio !!!

    Fantastic krishna..

    I got the result.... I did some changes in the above code according to my table structure & got it...

    Great job

    Last edited by karthizen; 06-04-2008 at 07:00 AM.

  4. #4
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: To find ratio !!!

    >>I did not get it right... I got the output as zero...

    If an employee does not has manager then it will display zero.

    I have tested it. It is working fine for me.

    Let me know what exactly your required output is ..


  5. #5
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: To find ratio !!!

    You have not provided table structures. Just I have given model query.

    Any how you have done modifications as per your requirement.


    Regards
    Krishna


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact