In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
SELECT
Log.User,
sum(if(hour(Log.endtime) = 0,
1,
0)) AS Midnight,
sum(if(hour(Log.endtime) = 1,
1,
0)) AS `1AM`,
sum(if(hour(Log.endtime) = 2,
1,
0)) AS `2AM`,
sum(if(hour(Log.endtime) = 3,
1,
0)) AS `3AM`,
sum(if(hour(Log.endtime) = 4,
1,
0)) AS `4AM`,
sum(if(hour(Log.endtime) = 5,
1,
0)) AS `5AM`,
sum(if(hour(Log.endtime) = 6,
1,
0)) AS `6AM`,
sum(if(hour(Log.endtime) = 7,
1,
0)) AS `7AM`,
sum(if(hour(Log.endtime) = 8,
1,
0)) AS `8AM`,
sum(if(hour(Log.endtime) = 9,
1,
0)) AS `9AM`,
sum(if(hour(Log.endtime) = 10,
1,
0)) AS `10AM`,
sum(if(hour(Log.endtime) = 11,
1,
0)) AS `11AM`,
sum(if(hour(Log.endtime) = 12,
1,
0)) AS `12PM`,
sum(if(hour(Log.endtime) = 13,
1,
0)) AS `1PM`,
sum(if(hour(Log.endtime) = 14,
1,
0)) AS `2PM`,
sum(if(hour(Log.endtime) = 15,
1,
0)) AS `3PM`,
sum(if(hour(Log.endtime) = 16,
1,
0)) AS `4PM`,
sum(if(hour(Log.endtime) = 17,
1,
0)) AS `5PM`,
sum(if(hour(Log.endtime) = 18,
1,
0)) AS `6PM`,
sum(if(hour(Log.endtime) = 19,
1,
0)) AS `7PM`,
sum(if(hour(Log.endtime) = 20,
1,
0)) AS `8PM`,
if(hour(Log.endtime) = 20,
sec_to_time(sum(time_to_sec(Log.endtime) - time_to_sec(Log.starttime))),
0) AS `8PM Time`,
sum(if(hour(Log.endtime) = 21,
1,
0)) AS `9PM`,
sum(if(hour(Log.endtime) = 22,
1,
0)) AS `10PM`,
sum(if(hour(Log.endtime) = 23,
1,
0)) AS `11PM`
FROM
(SELECT
atrtaxcert.ordertimeworked.user,
atrtaxcert.ordertimeworked.controlnumber,
atrtaxcert.ordertimeworked.starttime,
atrtaxcert.ordertimeworked.endtime,
timediff(atrtaxcert.ordertimeworked.endtime,
atrtaxcert.ordertimeworked.starttime) AS Worktime
FROM
atrtaxcert.ordertimeworked) AS Log
GROUP BY
Log.User
ORDER BY
NULL