473,668 Members | 2,460 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 1293
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
1992
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
79468
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 me to use sum function in update. Is there any other way to do this? Thanks. update test1 set tot_amount=sum(b.amount) from test1 as a join test2 as b on a.acc_no=b.acc_no
3
4499
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 it, I have a problem.
0
1423
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
2845
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 being summed for an event score. The total of the four event scores are the team score. Example below: Team 1 ====== Vault- 5, 6, 7, 8, 9, 10 EVENT SCORE: 10 + 9 + 8 = 27
1
3775
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
1057
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
2106
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 / kinisis_1b) * kinisis_1a))/(1 + fpa)) * 1.005) AS kinisis_1_total, SUM(((100c + 100e + ((100c / 100b)* 100a)) / (1 + fpa)) *1.005) AS 100ara_total, SUM(((super_1c + super_1e + ((super_1c / super_1b)* super_1a)) / (1 + fpa)) *1.005) AS super_1_total,
3
2651
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 (aspx.vb)
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8381
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8799
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8586
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7401
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6209
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
2026
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.