If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > how to sum all the salary in a year ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-08-11, 04:49
navedjobs navedjobs is offline
Registered User
 
Join Date: Sep 2011
Posts: 35
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 ?
Reply With Quote
  #2 (permalink)  
Old 12-08-11, 05:12
randirsa randirsa is offline
Registered User
 
Join Date: Nov 2011
Posts: 21
what is the issue with above code?. and provide the structure of emp_salary table.
Reply With Quote
  #3 (permalink)  
Old 12-08-11, 06:03
sql-programmers sql-programmers is offline
Registered User
 
Join Date: Oct 2009
Posts: 25
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)
__________________
SQL Server Programmers and Consultants
http://www.sql-programmers.com/
Reply With Quote
  #4 (permalink)  
Old 12-08-11, 06:21
navedjobs navedjobs is offline
Registered User
 
Join Date: Sep 2011
Posts: 35
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 .
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On