Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2011
    Posts
    47

    Unanswered: how to sum all the salary in a year ?

    i need to calculate the salary given to all employees in a year
    Code:
    select sum(emp_total_sal)from emp_salary
    how to modify this code to get what i need ?

  2. #2
    Join Date
    Nov 2011
    Posts
    21
    what is the issue with above code?. and provide the structure of emp_salary table.

  3. #3
    Join Date
    Oct 2009
    Posts
    27
    If you want total salary for a particular year of all employees then

    SELECT SUM(EMP_TOTAL_SAL)FROM EMP_SALARY WHERE YEAR(EMP_SALARY_DATE) = 2011

    If you want total salary for each year of all employees then

    SELECT SUM(EMP_TOTAL_SAL)FROM EMP_SALARY GROUP BY YEAR(EMP_SALARY_DATE)

    If you want total salary for a particular year of a employee then

    SELECT SUM(EMP_TOTAL_SAL)FROM EMP_SALARY WHERE YEAR(EMP_SALARY_DATE) = 2011 AND EMP_ID = '10'

    If you want total salary for each year of all employees then

    SELECT SUM(EMP_TOTAL_SAL)FROM EMP_SALARY WHERE EMP_ID = '10'
    GROUP BY YEAR(EMP_SALARY_DATE)

  4. #4
    Join Date
    Sep 2011
    Posts
    47
    Quote Originally Posted by sql-programmers View Post
    If you want total salary for a particular year of all employees then

    SELECT SUM(EMP_TOTAL_SAL)FROM EMP_SALARY WHERE YEAR(EMP_SALARY_DATE) = 2011

    If you want total salary for each year of all employees then

    SELECT SUM(EMP_TOTAL_SAL)FROM EMP_SALARY GROUP BY YEAR(EMP_SALARY_DATE)

    If you want total salary for a particular year of a employee then

    SELECT SUM(EMP_TOTAL_SAL)FROM EMP_SALARY WHERE YEAR(EMP_SALARY_DATE) = 2011 AND EMP_ID = '10'

    If you want total salary for each year of all employees then

    SELECT SUM(EMP_TOTAL_SAL)FROM EMP_SALARY WHERE EMP_ID = '10'
    GROUP BY YEAR(EMP_SALARY_DATE)
    thanks a lot man
    appreciate .

Posting Permissions

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