473,508 Members | 2,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SUM() Function is adding non existent values to the total . . .

CodeNoobster
52 New Member
Hi everyone, i have two tables, one for employee absence and another for employee overtime. Now for one employee in particular, he has been absent for 3 days and has worked overtime for one day. Now the respective values for both are 28.5 and 3.5 in terms of hours if I calculate the sum manually without sql based on the data from the database.

Now when I query this information and use the SUM() function to get the total for all hours when absent and hours for overtime, the result is 28.5 and 10.5.

28.5 represents the total number of hours absent from work and 3.5 (and 10.5 apparently) represent the total hours of overtime. Now why would the total for absence be correct and the total for overtime have 7 hours of non existent overtime?

Here's my query :

Expand|Select|Wrap|Line Numbers
  1. SELECT SUM(Emp_Absence.emp_Absence_work_hours) AS Total_Absense, SUM(Emp_Overtime.emp_overtime_hours) AS Total_Overtime
  2.  
  3. FROM ((Employee INNER JOIN Emp_Absence ON Employee.emp_num = Emp_Absence.emp_num) INNER JOIN Emp_Overtime ON Employee.emp_num = Emp_Overtime.emp_num)
  4.  
  5. WHERE (Employee.emp_fname = 'Timothy') AND (Emp_Overtime.emp_overtime_date LIKE '%October%2014') AND (Emp_Absence.Emp_Absence_date LIKE '%October%2014')
  6.  
Is the query incorrect? if so, how come the result for absence hours is valid?

Help and suggestions will be greatly appreciated.
Oct 18 '14 #1
2 1281
Rabbit
12,516 Recognized Expert Moderator MVP
The 3 absent records are matching up to the 1 overtime record. Which means the overtime record is being returned 3 times. Calculate the sums separately and join the results together so there's only one record per employee
Oct 18 '14 #2
CodeNoobster
52 New Member
Thanks rabbit, I just tried what you had suggested and it works.
Oct 22 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1983
by: Jean-Claude | last post by:
I have a table like this order_id price 1 -1000 2 2000 3 3000 4 4000 I want to know the total of the order amount, I use this query
4
79437
by: gooday | last post by:
Table test2 has multiple amounts for each account, I would like to sum the amounts for the same account and use the result to update the variable 'tot_amount' in table test1. But SQL does not allow...
3
4487
by: John Baker | last post by:
Hi: I have a field on a form that is names 125POP. It is currency. I can refer perfectly well to it in a text box when I want to add it to something as in: =+ HOWEVER when i want to sum...
0
1410
by: jwa6 | last post by:
I have a field on a form using the sum function made by this formula = Sum() format is 0000.00 this 'sum' seems to leave out cents. by that I mean if I have 3 values in ()
1
2839
by: Matthew J. Freel | last post by:
Currently I am trying to write a program to score a gymnastics meet for four events. Normally six competitors compete per event with the bottom 3 scores per event being dropped and the top three...
1
3763
by: jhayes7781 | last post by:
I am trying to add the values of two fields in one table. Not sure how to get the SUM function to make this work.
0
1049
by: parallax | last post by:
Hi guys, I am trying to sum the values of two fields in 2 tables check by the name of the people in mysql, i'm not sure how to get the SUM function to make this work. Danylo
3
2092
by: ORB30 | last post by:
Hi all, Does anyone know how to work arround this problem of sum function in php? The below query is giving me wrong results SELECT SUM(((kinisis_1c + kinisis_1e + ((kinisis_1c /...
3
2646
by: mrhua | last post by:
i have 50 column and i want to sum one by one , the total will show in the textbox that mean total of each column will show in each textbox , please take my hand to do it , because i m newbie ...
0
7129
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7333
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.