Online Tutorials & Training Materials | STechies.com
Register Login

Sum Salary Department Wise

Abhijeet Mudgal || 17 Mar 2015 4:48 pm || 11

Hello Experts,

Please tell me the solution that how to sum salary department wise as per image:

 

Thanks in Advance!


Comments

  • 06 Jul 2017 2:59 am Helpful Answer

    SELECT Name, sum(Salary), Dept FROM employees GROUP BY dept;

  • 17 Mar 2015 4:49 pm

    Elect sum((salary) * 10) from employee group by department. 

  • 17 Mar 2015 4:50 pm

    Absolutely right.

  • 17 Mar 2015 4:50 pm

    Please follow last line (Show Final Result). final result means: salary=1000*10=10000 its only one value but table contain 6 value. 6 value working same job and finally sum all result (6 value after multiple).

  • 17 Mar 2015 4:51 pm

    select sum( select salary*10 from employee ) from employee group by dept.

  • 17 Mar 2015 4:51 pm

    The first comment by Rohit is right. Can't make it righter anymore.

  • 17 Mar 2015 4:52 pm

    Select sum((salary*10)) from employee group by dept with roll up. It will give sum after every dept and grand sum of all departments.  let me know after trying, im giving this query of sql server, tested in sql server 2008 and 2014.

  • 17 Mar 2015 4:53 pm

    Select name,salary*10 as salary,dept from employee group by dept.

  • 17 Mar 2015 4:53 pm

    Select sum (salary*10) as salary from employee Group by dept with roll up.

  • 17 Mar 2015 4:54 pm

    declare
    min_level number:=1; -- Minimum Level Define $1
    next_level number:=500; -- Next Level Define $500

    min_comm number:=25; -- Minimum Commission Define 25%
    next_comm number:=30; -- Next Commission Define 30%

    v_result number;

    BEGIN
    select 
    case when sum(salamt)>min_level then sum(salamt*min_comm/100) end
    into v_result from salesdtl group by COMMID;
    DBMS_OUTPUT.PUT_LINE(v_result);
    END;
    ======================================
    This query has an error: "ORA-01422: exact fetch returns more than requested number of rows".
    I know this error is showing for "group by COMMID". But how can handle this error without no change "group by COMMID"

  • 17 Mar 2015 4:54 pm

    Either iterate through the records using a loop or use a collection. In other words Your v_result has to be a record type.

    Alternatively (If ur business logic allows this),
    Use rownum.