473,396 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sum up total hours for mutiple day entries

Can't figure out how to sum up a total of hours from same date entries.

Query:

SELECT work_hrs_for_day.empl_numbr, work_hrs_for_day.user_date, work_hrs_for_day.workday_totl, mech_hrs_for_day.day_totl

FROM work_hrs_for_day
LEFT JOIN mech_hrs_for_day

ON (work_hrs_for_day.user_date = mech_hrs_for_day.job_date) AND (work_hrs_for_day.empl_numbr = mech_hrs_for_day.empl_numbr)

WHERE work_hrs_for_day.empl_numbr= 699 AND
work_hrs_for_day.user_date >= 01/24/2008 AND
work_hrs_for_day.user_date >= 02/28/2008 AND
work_hrs_for_day.workday_totl > .5 AND
(abs(work_hrs_for_day.workday_totl - mech_hrs_for_day.day_totl) > .5 OR mech_hrs_for_day.day_totl is Null)

ORDER BY user_date


Result:

empl_number user_date workday_totl day_totl
699 1/3/2008 5.03 13.83
699 1/3/2008 8.8 13.83
699 1/4/2008 3.95 11.76
699 1/4/2008 7.81 11.76
699 1/7/2008 8.17 13.67
699 1/7/2008 5.5 13.67


Can't figure out how I can add the date totals so they only show the total of that day!
Mar 14 '08 #1
1 1686
Delerna
1,134 Expert 1GB
If I understand correctly
Expand|Select|Wrap|Line Numbers
  1. SELECT a.empl_numbr, a.user_date, 
  2.        sum(a.workday_totl) as workday_totl, 
  3.        sum(b.day_totl) as day_totl
  4. FROM work_hrs_for_day a
  5. LEFT JOIN mech_hrs_for_day b
  6. ON a.user_date = b.job_date AND a.empl_numbr = b.empl_numbr
  7. WHERE a.empl_numbr= 699 AND 
  8.       a.user_date >= 01/24/2008 AND 
  9.       a.user_date >=  02/28/2008 AND  
  10.       a.workday_totl > .5 AND 
  11.       abs(a.workday_totl -b.day_totl) > .5 OR a.day_totl is Null
  12. GROUP BY a.empl_numbr,, a.user_date
  13. ORDER BY user_date
  14.  
I added the group by clause at the end
and the sum aggregates in the select clause
I also gave the tables an alias to make the query a bit easier to read
and I wraped the query In code tags, again to make it easier to read.
You should do that for your code when asking a question.
Easy to read for us = more likely to get an answer for you
Mar 18 '08 #2

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

Similar topics

4
by: Stephen Young | last post by:
Hello Have a bit of a problem, im trying to get the total number of hours:minutes for all actions over the month in a query, have tried two methods to no luck... Duration This Month:...
3
by: Hai Nguyen | last post by:
Hi all I was attempting to insert multiple row by using a loop into a database.A table has 2 primary keys and one regular field (PR) (PR) ID Project Ans 1 2 a 1 ...
3
by: Beowulf | last post by:
I have data coming from a telephony system that keeps track of when an employee makes a phone call to conduct a survey and which project number is being billed for the time the employee spends on...
2
by: dath | last post by:
Hi, Not really a programmer here, but have been forced into the role. I was asked to develop a basic time sheet for employees to enter time. I developed the Table without a problem. I then...
4
by: rbronco28 | last post by:
I am pretty new at doing web development. I can make simple pages, but recently received a request from a small limo business I do web development for. We are currently working on a reservation...
8
RobH
by: RobH | last post by:
Hi.. I have a table of Products and StateID. The products with a field for which states they are availble using the codes from the StateID table tbl-Products ProductID Description ...
1
by: silversubey | last post by:
I am using a query to total hours (Cltbudget.CBudhours) and dollars (CltBudget.CBudFee) Grouped by client names (Cltbudget.CBudCltName). here is the Query: SELECT CltBudget.CBudCltName AS Client...
1
by: tcertain | last post by:
I am totally duh at javascript although I have 2 books trying to learn it. I am trying to add values to a form and have a calculate total at end. this is my form script. I have hours at end of...
3
by: lizBeth | last post by:
Hi all, i seem to have gotten stuck on this coursework, i am unsure as to how to implement a method in the main class to calculate the sum of all employees monthly salaries. Everything...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.