|
Title: Total Hours Per Pay Period Post by: rdivilbiss on April 02, 2008, 10:02:07 AM I have a time clock application.
The timeclock table is: Code: id int(11) userid varchar(25) timein datetime timeout datetime worked decimal(4,2) To get a list of the dates and time worked for each day for a pay period I can do: Code
Can this be modified to also return the entire total sum of time worked without having to run another query? Title: Re: Total Hours Per Pay Period Post by: CrYpTiC_MauleR on April 02, 2008, 01:34:59 PM Ok so each row is just a single time punch and above query is getting all punches for a specific time period. So are you asking how to get the time punches for that period all added together?
Title: Re: Total Hours Per Pay Period Post by: VGR on April 03, 2008, 07:13:28 AM the answer is "NO" ; you can probably do it in one signle "query" with a sub-query (so in fact, two queries) but your ODBC driver wouldn't like it (I guess you use ODBC because of the silly unnecessary backquotes around column names)
given you've in fact two queries to run, you'd better separate them. The DB engine is building a temporary table anyway, and in case of the subquery an other table. So build tables yourself, unless you want to rely on the query cache to speed up repetitive queries for results ;-) you could add a column to each user containing - if not the current day - that total amount and thus a simple sum() on that user would give you the total and a simple sum() on all users would give the grand total, all perperiods or you could build a separate table "user_time" to hold user_id and total per day, then use it as above. Title: Re: Total Hours Per Pay Period Post by: rdivilbiss on April 03, 2008, 10:45:01 PM Thank you both for your response.
I came to the same conclusion, so I wrote a procedure and put the results in a temporary table, then query from that. Actually, then I'm running several queries but the results are in single digit milliseconds and it is a low use application, so that will do nicely. As to ODBC, never use it. I do however use prepared statements for all my web forms and prefer the formality of the back tics.
Powered by SMF 1.1 RC2 |
SMF © 2001-2005, Lewis Media
Joomla Bridge by JoomlaHacks.com |