calculation of Salary to the top or to the bottom of the hierarchy

Hello all,.

How to get the total salary wound of lower level to a higher level of the hierarchy?

We can get the hierarchy of the employee and the salary of hr.employees table using the suite of applications:
select level, last_name, salary
from hr.employees
start with employee_id = (select employee_id
                                     from  hr.employees
                                     where manager_id IS NULL
                                    )
connect by prior employee_id  = manager_id
How to get the salary rolled up to a higher level with sql as follows?
level      last_name        salary        total salary

2         Kochhar           17000          109800
3         Whalen              4400            4400
3         Mavris                6500            6500
3         Bae                 10000           10000
3         Higgins             12000          20300
4             Gietz              8300           8300
3         Greenberg        12000          51600
4            Faviet             9000            9000
4            Chen              8200            8200
4            Sciarra            7700             7700
4            Urman            7800             7800
4            Popp              6900             6900
Here all level 4 level 3 Greenberg rolled up to level 3, then level 4 under Higgins rolled up to level 3, then all the level 3 under Kochar wrapped at level 2.

Is it possible in sql?

Thanks for your help.

Edited by: rxshah May 14, 2010 03:45

(B-)

select level, last_name, salary,
(select sum(b.salary) from hr.employees b
 start with b.employee_id=a.employee_id
 connect by prior b.employee_id  = b.manager_id)
from hr.employees a
start with employee_id = (select employee_id
                                     from  hr.employees
                                     where manager_id IS NULL
                                    )
connect by prior employee_id  = manager_id;

Tags: Database

Similar Questions

  • The calculator program working if the second number is more than 1 digit.

    I was setting up a calculator on labview, which works except for when I entered that a second number of the calculator does not have the correct value if the second number is more than 1 digit. I think it's down to the use of shift registers and result of the operation is forgotten when a key is pressed. I joined the program, if someone could confirm that this is the problem / suggest potential ways around this problem that would be a great help

    RavensFan wrote:

    Use default if Unwired.  Several of your tunnels are defined in this way, including the orange wire (double-precision) where you store your first operand.

    If you run an event where a wire is not connected through the tunnel will display by default (empty for string, double zero) and the shift register will then forget what he was originally in it.

    I think you meant not to use the default value if Unwired?  I think you have to tell him to use linked entry Tunnel--> Create and wire Unwired cases instead?

  • What is this calculation of parameters of the analysis executable average reliability has stopped working and was closed

    What is this calculation of parameters of the analysis executable average reliability has stopped working and was closed

    Hi Mary,

    ·         You did any computer change?

    ·         When we get this message?

    Follow the steps mentioned below:

    How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7

    http://support.Microsoft.com/kb/929135   
    Note: when you have completed troubleshooting by clean boot follow steps 7 to place the computer in his usual way

    Start your computer in safe mode

    http://Windows.Microsoft.com/en-us/Windows7/start-your-computer-in-safe-mode

    If none of the options work perform the system restore

    What is system restore?

    http://Windows.Microsoft.com/en-us/Windows-Vista/what-is-system-restore

    Reply back with the results

  • 11 GR 2 forms: display windows calculator on before calling the form?

    I called the windows calculator in my forms through

    AppID: = DDE. App_Begin ('C:\Windows\system32\calc.exe', DDE. APP_MODE_MAXIMIZED);

    DDE. App_Focus (appid);

    which trigger key, but when I press the button the calculator is displayed but not active, I want the calculator should display on the front of my form (call the adapted form).

    I use forms GR 11, 2.

    As mentioned Amatu, what you do will not work as expected when you deploy your application in a production facility.  I suspect that you run the form directly from the form Builder on your local computer.

    To display a calculator to an end user, you'll either need add WebUtil to your application and use the Windows calculator or calculator Java Bean.  The Java Bean option is probably a better because with it, you can actually have the value in the calculator sent to the form.  The disadvantage of the use of a Java Bean, it's that you have to design it.  There are some great examples here:

    http://Forms.PJC.Bean.over-blog.com/article-35505095.html

    With WebUtil, the call might look like this:

    WEBUTIL_HOST. HOST ('calc');

    There is also a non-blocking option which allows the user to have both the open Calculator and still have access to the form.  Using the above, the form will be locked until the calculator is closed.  Refer to the manufacturer for more information about WebUtil, duties and requirements.

  • Getting the name of the top of the hierarchy of the inventory in a VC

    When you cross a VC inventory, what is the type of the object at a higher level? I think it's a folder - that's what I'm doing once the connection and I browse the hierarchy correctly.

    File fd (sc.rootFolder);

    Where sc is the ServiceContent instance I understand well after the connection to the server.

    The VC that I use is named STORAGE2 and the top-level object is also named STORAGE2 - but when I ask the name of the object "fd" he gave a name "data centers". When I ask the other folders in the hierarchy down, I make own name except for this one.

    Am I wrong in thinking that the top-level of the VC object is a folder? How can I name own derieve for this object?

    Thank you

    . / Siva.

    "Data centers" is the name of the rootFolder.  The next type of the object in the tree is defined entities of data center.  Take a look at the ServiceInstance object to see the tree in the API documentation.

    ServiceInstance

    In the user of the vSphere Client interface, the rootFolder is hidden, and they show rather the name of vCenter. If you want to emulate the appearance of the user interface of vSphere, you need to hide some of the items of base directory, but they are there in the real inventory tree in code.

  • Script to find the base salary of the prospective employee

    HRMS dear Experts,

    I develop employee list-report - I need to include all the number of employees and their base salary. That's (current and prospective employee) category "Employee" and "worker of the Contingent.

    For the employee category I take table per_pay_proposals - linking employee-> person - ID ID assignment number-->--> ID of Type person.

    "For category - 'Potential worker' need, the name of the table that store base base salary for the prospective employee.

    Version:

    Oracle Applications: 12.0.6

    RDBMS: 10.2.0.3.0

    Thank you

    We got the name of the base table this morning.

    It's per_all_assignments_F - class title

    Thanks to my manager who is an Expert in Oracle on all...

  • Salary and the date of validation at the OS level.

    Hi all

    I have two wage and Date fields both are present at the level of the OS

    I need to write a validation that if date of birth is entered on the user interface is more than 50 years as of today pay should not be less than 5000

    Ex: if entered date is 02/02/1961 and entered salary is 4500, then it must raise an error message when the button is clicked.

    There are to many validations customized at the OS level, but exactly where this is done.

    Thank you
    Arun

    Hello

    You can use a script expression for the attribute of salary at the entity level to calculate the age (DOB-based) and then trigger the error based on two conditions.

    Ex:

    Calendar now = Calendar.getInstance();
    Calendar dob = Calendar.getInstance();
    dob.setTime(); //Change it to the name of the attribute which holds the DOB.
    
    int year1 = now.get(Calendar.YEAR);
    int year2 = dob.get(Calendar.YEAR);
    int age = year1 - year2;
    int month1 = now.get(Calendar.MONTH);
    int month2 = dob.get(Calendar.MONTH);
    if (month2 > month1) {
      age--;
    } else if (month1 == month2) {
      int day1 = now.get(Calendar.DAY_OF_MONTH);
      int day2 = dob.get(Calendar.DAY_OF_MONTH);
      if (day2 > day1) {
        age--;
      }
    }
    
    if(age>=50 && newValue<5000) {
      adf.error.raise("SOME_ERROR")
      return false;
    }
    else return true;
    

    Define SOME_ERROR in the section of the error of the Add Rule dialog box.

    Arun-

  • How do you create a calculation that automatically updates the changes?

    Hi all

    I am trying to create a named using subtraction calculation. That's how it is stated:

    KM

    -KG

    Field1 =

    -Field2

    = GM (liquid)

    The tab calculate for zone 1, I wrote in the simplified field notation:

    KM - KG

    And the tab calculate = GM (liquid), I wrote it in simplified field notation:

    Field1 Field2

    And it all works perfectly that I change all the totals in the fields of Field2 or KG or KM .

    If changes in these areas they don't update automatically.

    How can I make them to update automatically?

    Any help would be much appreciated.

    Thank you very much.

    Bridie

    To set the order of computation of field, go first in forms editing mode (Tools > forms > change), then: tasks > other tasks > edit fields > set field calculation order

    Order the fields in a list of everything that makes sense for your form. Be sure to do it again once the form works as you want to ensure that it is always configured correctly.

  • Could not find the calculation Manager option in the menu

    Hi all

    I have configured the calculation Manager in my machine [version: 11.1.2].] I can't find the calculation Manager option in the menu [Navigate-> administer-> calculation Manager].
    Calculation Manager is running. Kindly guide me to overcome.

    Thanks and greetings
    Alizée

    If calc manager has been installed after the configuration of the web, re-run the web comfiguration step. You may also cycle in the service of SST on the Foundation subsequently.

    Kind regards

    John A Booth

  • How can I get the maximum salary of the first ascending

    Hello

    How can I get the maximum salary of the first in ascending order.
    I need the sql query.

    want my output:

    Emp_name salary
    A 5000
    SS 100
    300 AA
    DD 700
    WW 2000



    Thank you
    Walid.

    Here is an example:

    SQL> with mytable as
      2  ( select 'aa' as col1,  300 col2 from dual union all
      3    select 'ss' as col1,  100 col2 from dual union all
      4    select 'a'  as col1, 5000 col2 from dual union all
      5    select 'dd' as col1,  700 col2 from dual union all
      6    select 'ww' as col1, 2000 col2 from dual )
      7  select col1, col2
      8  from   mytable
      9  order by decode(row_number() over (order by col2 desc),1,0,1),col2;
    
    CO       COL2
    -- ----------
    a        5000
    ss        100
    aa        300
    dd        700
    ww       2000
    
    SQL>
    

    Nicolas.

  • Capture the salary of the employee in different currencies in a single enterprise group

    Hello

    Scenario: According to group unique buiness, information of the employees of several countries are counted (as there may be very few employees in each of these countries).

    Status of pay is NOT implemented, how we capture information on country-specific employee wages to say, capture of an employee's salary in different currencies under unique business group.

    Thank you

    You can use Add'l salary admin. Details FDF to capture the currency and converted value. Salary of the hand will be in a base currency.

    Thank you

  • OBIEE BI answers: measures bad aggregation at the top level of the hierarchy

    Hi all,
    I have the following problem. I hope to be clear in my English because it is somewhat complicated to explain.

    I did following:

    ID of drugs classified in quantity
    1 9
    2 4
    1 3
    2 2

    and drugs following table:

    Drug brand Id brand Description drug whose active ingredient Id drug whose active principle Description
    Aulin Nimesulide 1 1
    2 Asprina 2 Acetilsalicilico

    In AWM, I've defined a Dimension of drugs based on the following hierarchy: drug whose active ingredient (parent) - brand name of medication (sheet) mapped as Description:

    The active ingredient of drug = drug Active ingredient Id of my Table of drugs (pharmaceutical = Description of the active ingredient LONG DESCRIPTION attribute)
    Pharmaceutical brand Description = drug brand Id of my drugs Table (LONG DESCRIPTION = Description of drug brand attribute)

    Indeed, in my cube, I have traced pharmaceutical leaf-level brand Description = Id of the drug of my fact table. In AWM drugs Dimension is mapped as Sum aggregation operator

    If I select on answers drug whose active ingredient (parent of my hierarchy) and the quantity, in my view, after the result

    Description of the active ingredient drugs classified in quantity
    Acetilsalicilico 24
    Nimesulide 12

    indeed of the correct values

    Description of the active ingredient drugs classified in quantity
    Acetilsalicilico 12
    Nimesulide 6

    EXACTLY the double! But if I dig drug Description of the active ingredient Acetilsalicilico I can't see correctly:

    Drug whose active ingredient Description pharmaceutical brand classified in quantity Description
    Acetilsalicilico
    -12 Aspirina
    Total 12

    Aggregation of evil is only at the top level of the hierarchy. The aggregation on the lower level of the hierarchy is correct. Perhaps the answers also amount Total line? Why?

    I'm frustrated. I ask your help, please!

    Giancarlo

    OK your on 10G but the view of the cube and the obligation to limit the levels in the LTS in the RPD is valid in both.
    I think we found the problem,
    Go to each source logical table this logic table (x 2 in your case you have two levels) and on the content tab, window background ' use this "Clause Where" filter to limit the rows returned. »
    Open the expression builder, locate LEVEL_NAME according to your cube and limit accordingly, it is to say LEVEL_NAME = "BRAND_DESCRTIPION" for the aggregation BRAND_DESCRIPTION LTS and LEVEL_NAME = "XXXX" in detail, SFF, where XXXX is the name of level of hierarchy in your cube for details (leaves) records.

    Can you try that and let us know?
    Thank you
    Alastair

  • Using the calculation script to write the value of the variable Substitution in a file

    Hello

    I am trying to use the calculation script to write the value of Substitution variable in a text file.
    I use the dataexport command. But it is not able to write values in the text file.

    Any help is appreciated.

    Thank you.

    MaxL would display variable. See: http://download.oracle.com/docs/cd/E10530_01/doc/epm.931/html_esb_techref/maxl/ddl/statements/dispvarb.htm

    BTW, I mostly prefer Esscmd MaxL. I think that makes me a heretic, but I don't understand why I don't want to type more rather than less to get the same result.

    Running a calc:
    Esscmd - RUNCALC 2 calcname
    MaxL - run calculation Sample.Basic.calcname;

    To be fair, Esscmd requires a dbname appname SELECT before the RUNACALC, but it is always less striking.

    However, time is running, so I don't have too. And of course, MaxL now has many things that Esscmd doesn't like Esscmd is obsolete.

    I always use Esscmd to run scripts of calc I can actually watch the output in real time as opposed to MaxL that exports the console at the end of execution.

    Kind regards

    Cameron Lackpour

  • How can I get the second and third highest salary from the emp table

    How can I get the second and third highest salary from the emp table in the ecah Department
    SQL> ed
    Wrote file afiedt.buf
    
      1  select empno, ename, sal, deptno
      2  from (
      3    select empno, ename, sal, deptno, dense_rank() over (partition by deptno order by sal desc) as rn
      4    from emp
      5    )
      6* where rn in (2,3)
    SQL> /
    
         EMPNO ENAME             SAL     DEPTNO
    ---------- ---------- ---------- ----------
          7782 CLARK            2450         10
          7934 MILLER           1300         10
          7566 JONES            2975         20
          7876 ADAMS            1100         20
          7499 ALLEN            1600         30
          7844 TURNER           1500         30
    
    6 rows selected.
    
    SQL>
    
  • Calculation of average in the child-parent relationship

    Hello

    Oracle database version: 11.2.0.1.0

    Currently I'm having a problem of query to calculate the average value. Using the usual average query does not get the result I'm looking for. Because I'm not good with English, I will try to explain for example instead.

    Data table
    COD_A     COD_B     SALES     QTY     PRICE
    0000302     00003               6.09
    0000302     00003               11.7
    0000304     00003               14.08
    0000306     00003               8.87
    0000306     00003     3105     510     4.63
    0000306     00003               4.65
    0000308     00003     18091     1456     12.43
    If I try to calculate the average price of COD_A, I have the correct answer, as expected.
    SELECT COD_A, SUM(SALES), SUM(QTY), AVG(PRICE) FROM VDATATABLE GROUP BY COD_A ORDER BY 1;
    Average price per COD_A
    COD_A     SUM(SALES)     SUM(QTY)     AVG(PRICE)
    0000302                                8.895
    0000304                           14.08
    0000306     3105         510                6.05
    0000308     18091        1456              12.43
    --------------

    If I try to calculate the average price of COD_B, I don't have my expected result.
    SELECT COD_B, SUM(SALES), SUM(QTY), AVG(PRICE) FROM VDATATABLE GROUP BY COD_B ORDER BY 1;
    Average price per COD_B (1)
    COD_B     SUM(SALES)     SUM(QTY)     AVG(PRICE)
    00003     21196             1966              8.92142857142857
    The result I'm looking for is
    WITH W1 AS
    (SELECT COD_B, SUM(SALES) SALES, SUM(QTY) QTY, AVG(PRICE) PRICE FROM VDATATABLE GROUP BY COD_A,COD_B)
    SELECT COD_B, SUM(SALES), SUM(QTY), AVG(PRICE) FROM W1 GROUP BY COD_B;
    Average price of COD_B (2)
    COD_B     SUM(SALES)     SUM(QTY)     AVG(PRICE)
    00003     21196              1966         10.36375
    ---------

    So, the way I want to calculate the average price is the average of the lower child attribute and continue the average to its parent attribute. Currently I can get the result by using the clause, but the hierarchy available not only stops at COD_B, there is more (e.g. COD_C, COD_D, so on), so the foregoing WITH the query "seems" to be inflexible. If I want to ask the COD_C aggregation, I might have to put another COMPONENT in the query.

    So I was wondering is there any other better method to get the result I want? Something more dynamic as a recursive function or integrated maybe?

    Thank you

    Published by: user10620897 on October 19, 2011 04:15

    Hello

    Whenever you have questions, please post CREATE TABLE and INSERT statements for your sample data.
    Always tell what version of Oracle you are using. Don't say something vague, like "11g" in a label where it is easy to miss. Tell exactly what version you have in the body of the message. For example "I'm using Oracle 11.1.0.7.0.

    If you have N levels in the hierarchy, then using subqueries N-1, as you already do, might be the best way.

    If you use Oracle 11.2, you may be able to obtain these results by using a WITH recursive clause.

    Here's another approach to obtain the results desired with a hierarchy of level 2:

    WITH     got_cnt          AS
    (
         SELECT     cod_a, cod_b, sales, qty, price
         ,     COUNT (*) OVER (PARTITION BY cod_a, cod_b)     AS cnt
         FROM     data
    )
    SELECT       cod_b
    ,       SUM (sales)               AS sum_sales
    ,       SUM (qty)                  AS sum_qty
    ,       SUM (price / cnt)
           / COUNT (DISTINCT cod_a)     AS avg_price
    FROM       got_cnt
    GROUP BY  cod_b
    ;
    

    I think you can do this job for any number of levels without adding another subquery for all levels. You may need to add expressions to COUNT more for all levels, and the query only works for a fixed number of levels.

Maybe you are looking for