Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2010
    Location
    Bangalore
    Posts
    7

    Unanswered: To find the emp sal

    hi ,
    plse check the attacement and could you pls tell me how to solve it
    Attached Thumbnails Attached Thumbnails query1.bmp  

  2. #2
    Join Date
    Mar 2010
    Location
    Vienna, Austria
    Posts
    149
    Pretty simple:

    If an individual has no subordinates, print her/his salary, otherwise subtract the salaries of the subordinates from the salary using tree walking.

    (You didn't expect us to do your homework completely, did you ?)
    "There is always an easy solution to every problem - neat, plausible, and wrong."
    -- H.L. Mencken

  3. #3
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Tree isn't necessary (if I understood what's being said); a simple sum could do the job, I guess ...
    Code:
    SQL> select
      2    t.empid,
      3    t.lastname,
      4    t.cumsalary - nvl(x.sum_cum, 0) my_salary
      5  from test t,
      6       (select mgrid, sum(cumsalary) sum_cum
      7        from test
      8        group by mgrid
      9       ) x
     10  where x.mgrid (+) = t.empid
     11  order by t.empid;
    
         EMPID LASTNAME              MY_SALARY
    ---------- -------------------- ----------
          1001 SCOTT                      5000
          1002 TOM                        1300
          1003 VEER                        700
          1004 RAM                         500
          1005 RAGU                       1300
          1006 BUSH                        800
          1007 HUSS                        600
          1008 GOPI                        400
    
    8 rows selected.
    
    SQL>

  4. #4
    Join Date
    Apr 2010
    Location
    Bangalore
    Posts
    7
    thanks its working fine

  5. #5
    Join Date
    Apr 2010
    Location
    Bangalore
    Posts
    7
    Quote Originally Posted by magicwand View Post
    Pretty simple:

    If an individual has no subordinates, print her/his salary, otherwise subtract the salaries of the subordinates from the salary using tree walking.

    (You didn't expect us to do your homework completely, did you ?)

    Dear magicwand,
    Thanks for giving the explanation.
    ( i am new in database concepts . i have my own approch to this but i want to know any easy way to do this .what u feel about it )

  6. #6
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Although you don't ask me, here's what I think: if you have your own approach, you should have presented it so that we would see what you already have done and - if necessary - improve it, comment it, or suggest another approach.

    What you did was more or less please, do my homework. If you learnt something, good. If not, well, from a long term point of you it will be to your disadvantage.

  7. #7
    Join Date
    Apr 2010
    Location
    Bangalore
    Posts
    7
    Quote Originally Posted by Littlefoot View Post
    Although you don't ask me, here's what I think: if you have your own approach, you should have presented it so that we would see what you already have done and - if necessary - improve it, comment it, or suggest another approach.

    What you did was more or less please, do my homework. If you learnt something, good. If not, well, from a long term point of you it will be to your disadvantage.
    hi littlefoot i already told that i am new in database field and the forums also . so don't think any think bad about me .

  8. #8
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    I don't.

    [Cool.

    "The message you have entered is too short. Please lengthen your message to at least 10 characters."

    Now it is longer than 10 characters, I guess.]

  9. #9
    Join Date
    Mar 2010
    Location
    Vienna, Austria
    Posts
    149
    Littlefoot,

    I'm afraid, your solution above will not work with additional hierarchy levels ...
    "There is always an easy solution to every problem - neat, plausible, and wrong."
    -- H.L. Mencken

  10. #10
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Post a few sample lines (in the same format as the OP posted in his first post) and I'll take a look.

Posting Permissions

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