Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Calculate Working hours

Author  Topic 

baktha.thalapathy
Starting Member

7 Posts

Posted - 2010-04-28 : 11:02:39
Hello,

I am using the below sql query to calculate working hours. The problem which i am facing is that query is taking lot of time to calculate the working hours. Please help to reduce the execution time of this query or if there is any other way to calculate working hours

The following query take 63.499 sec


SELECT sql_calc_found_rows gstime,
MAX(stoptime) AS mx,
MIN(starttime) AS mn,
Sec_to_time(SUM(Time_to_sec(Timediff(stoptime, starttime)))) AS totalworktime
FROM (SELECT gstime,
gstime AS stoptime,
Coalesce((SELECT MAX(b.gstime)
FROM xydata b
WHERE objectid = '17'
AND clientid = '1'
AND gstime > '2010-04-20 08:22:27'
AND gstime < '2010-04-26 10:22:27'
AND b.objectid = a.objectid
AND b.gstime < a.gstime), gstime) AS starttime
FROM xydata a
INNER JOIN fm4features f
ON f.id = a.id
WHERE objectid = '17'
AND clientid = '1'
AND gstime > '2010-04-20 08:22:27'
AND gstime < '2010-04-26 10:22:27'
AND f.dataid = '1'
AND f.VALUE = '1') derived
GROUP BY Date_format(gstime, '%Y-%m-%d')
ORDER BY gstime ASC

please help me how do i change the query to reduce the sec.

Bakthavachalam E

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-28 : 11:06:05
is this sql server? I dont think it is seeing functions like SEC_TO_TIME, TIMEDIFF,etc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

baktha.thalapathy
Starting Member

7 Posts

Posted - 2010-04-28 : 11:26:31
thanks for your response,

Yes it's mysql server

please help me how do i reduce the query execution time

Bakthavachalam E
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-28 : 11:34:53
then you're in wrong forum!
This is MS SQL Server forum and solutions provided here are guaranteed to work only in SQL Server

please post in MySQL forums like www.dbforums.com

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -