Code:
SELECT
coding_log.`date`,
coding_log.last_name,
`user`.tl,
batch_log.`client`,
batch_log.service,
sum(coding_log.break_hours) as 'Total Break',
Hour(if (min(coding_log.time_start) <= '16:00' and max(coding_log.time_end) >= '16:00',
subtime(max(coding_log.time_end),'16:00'), if(min(coding_log.time_start)
and max(coding_log.time_end) <= '16:00', '0', subtime(max(coding_log.time_end),
min(coding_log.time_start))))) + minute(if (min(coding_log.time_start) <= '16:00' and max(coding_log.time_end) >= '16:00',
subtime(max(coding_log.time_end),'16:00'), if(min(coding_log.time_start)
and max(coding_log.time_end) <= '16:00', '0', subtime(max(coding_log.time_end),
min(coding_log.time_start)))))/60 as 'Over Time',
HOUR(subtime(SEC_TO_TIME(SUM(TIME_TO_SEC(SUBTIME(coding_log.time_end,coding_log.time_start)))),
if(min(coding_log.time_start) <= '16:00' and max(coding_log.time_end) >= '16:00',
subtime(max(coding_log.time_end),'16:00'), if(min(coding_log.time_start)
and max(coding_log.time_end) <= '16:00', '0', subtime(max(coding_log.time_end),
min(coding_log.time_start)))))) +
MINUTE(subtime(SEC_TO_TIME(SUM(TIME_TO_SEC(SUBTIME(coding_log.time_end,coding_log.time_start)))),
if(min(coding_log.time_start) <= '16:00' and max(coding_log.time_end) >= '16:00',
subtime(max(coding_log.time_end),'16:00'), if(min(coding_log.time_start)
and max(coding_log.time_end) <= '16:00', '0', subtime(max(coding_log.time_end),
min(coding_log.time_start))))))/60 as 'Regular Hours',
sum(Hour(IF(coding_log.`Time_End`<coding_log.`Time_Start`,
addtime('24:00:00', timediff(coding_log.`Time_End`, coding_log.`Time_Start`)),
timediff(coding_log.`Time_End`, coding_log.`Time_Start`)))) +
(sum(minute(IF(coding_log.`Time_End`<coding_log.`Time_Start`,
addtime('24:00:00', timediff(coding_log.`Time_End`, coding_log.`Time_Start`)),
timediff(coding_log.`Time_End`, coding_log.`Time_Start`))))/60) as 'Total Man Hours',
"coding_log" as 'Data Process'
FROM
coding_log left join `user` on (`user`.last_name = coding_log.last_name)
inner join batch_log on (batch_log.job_number = coding_log.job_no)
where batch_log.total_batches is not null
group by
coding_log.`date`,
coding_log.last_name,
batch_log.`client`
union
SELECT
key_entry_log.`date`,
key_entry_log.last_name,
`user`.tl,
batch_log.`client`,
batch_log.`service`,
sum(key_entry_log.break_hours) as 'Total Break',
Hour(if (min(key_entry_log.time_start) <= '16:00' and max(key_entry_log.time_end) >= '16:00',
subtime(max(key_entry_log.time_end),'16:00'), if(min(key_entry_log.time_start)
and max(key_entry_log.time_end) <= '16:00', '0', subtime(max(key_entry_log.time_end),
min(key_entry_log.time_start))))) + minute(if (min(key_entry_log.time_start) <= '16:00' and max(key_entry_log.time_end) >= '16:00',
subtime(max(key_entry_log.time_end),'16:00'), if(min(key_entry_log.time_start)
and max(key_entry_log.time_end) <= '16:00', '0', subtime(max(key_entry_log.time_end),
min(key_entry_log.time_start)))))/60 as 'Over Time',
HOUR(subtime(SEC_TO_TIME(SUM(TIME_TO_SEC(SUBTIME(key_entry_log.time_end,key_entry_log.time_start)))),
if(min(key_entry_log.time_start) <= '16:00' and max(key_entry_log.time_end) >= '16:00',
subtime(max(key_entry_log.time_end),'16:00'), if(min(key_entry_log.time_start)
and max(key_entry_log.time_end) <= '16:00', '0', subtime(max(key_entry_log.time_end),
min(key_entry_log.time_start)))))) +
MINUTE(subtime(SEC_TO_TIME(SUM(TIME_TO_SEC(SUBTIME(key_entry_log.time_end,key_entry_log.time_start)))),
if(min(key_entry_log.time_start) <= '16:00' and max(key_entry_log.time_end) >= '16:00',
subtime(max(key_entry_log.time_end),'16:00'), if(min(key_entry_log.time_start)
and max(key_entry_log.time_end) <= '16:00', '0', subtime(max(key_entry_log.time_end),
min(key_entry_log.time_start))))))/60 as 'Regular Hours',
sum(Hour(IF(key_entry_log.`Time_End`<key_entry_log.`Time_Start`,
addtime('24:00:00', timediff(key_entry_log.`Time_End`, key_entry_log.`Time_Start`)),
timediff(key_entry_log.`Time_End`, key_entry_log.`Time_Start`)))) +
(sum(minute(IF(key_entry_log.`Time_End`<key_entry_log.`Time_Start`,
addtime('24:00:00', timediff(key_entry_log.`Time_End`, key_entry_log.`Time_Start`)),
timediff(key_entry_log.`Time_End`, key_entry_log.`Time_Start`))))/60) as 'Total Man Hours',
"key_entry_log" as 'Data Process'
FROM
key_entry_log left join `user` on (`user`.last_name = key_entry_log.last_name)
inner join batch_log on (batch_log.job_number = key_entry_log.job_no)
where batch_log.total_batches is not null
group by
key_entry_log.`date`,
key_entry_log.last_name,
batch_log.`client`
union
SELECT
scan_log.`date`,
scan_log.last_name,
`user`.tl,
batch_log.`client`,
batch_log.`service`,
sum(scan_log.break_hours) as 'Total Break',
Hour(if (min(scan_log.time_start) <= '16:00' and max(scan_log.time_end) >= '16:00',
subtime(max(scan_log.time_end),'16:00'), if(min(scan_log.time_start)
and max(scan_log.time_end) <= '16:00', '0', subtime(max(scan_log.time_end),
min(scan_log.time_start))))) + minute(if (min(scan_log.time_start) <= '16:00' and max(scan_log.time_end) >= '16:00',
subtime(max(scan_log.time_end),'16:00'), if(min(scan_log.time_start)
and max(scan_log.time_end) <= '16:00', '0', subtime(max(scan_log.time_end),
min(scan_log.time_start)))))/60 as 'Over Time',
HOUR(subtime(SEC_TO_TIME(SUM(TIME_TO_SEC(SUBTIME(scan_log.time_end,scan_log.time_start)))),
if(min(scan_log.time_start) <= '16:00' and max(scan_log.time_end) >= '16:00',
subtime(max(scan_log.time_end),'16:00'), if(min(scan_log.time_start)
and max(scan_log.time_end) <= '16:00', '0', subtime(max(scan_log.time_end),
min(scan_log.time_start)))))) +
MINUTE(subtime(SEC_TO_TIME(SUM(TIME_TO_SEC(SUBTIME(scan_log.time_end,scan_log.time_start)))),
if(min(scan_log.time_start) <= '16:00' and max(scan_log.time_end) >= '16:00',
subtime(max(scan_log.time_end),'16:00'), if(min(scan_log.time_start)
and max(scan_log.time_end) <= '16:00', '0', subtime(max(scan_log.time_end),
min(scan_log.time_start))))))/60 as 'Regular Hours',
sum(Hour(IF(scan_log.`Time_End`<scan_log.`Time_Start`,
addtime('24:00:00', timediff(scan_log.`Time_End`, scan_log.`Time_Start`)),
timediff(scan_log.`Time_End`, scan_log.`Time_Start`)))) +
(sum(minute(IF(scan_log.`Time_End`<scan_log.`Time_Start`,
addtime('24:00:00', timediff(scan_log.`Time_End`, scan_log.`Time_Start`)),
timediff(scan_log.`Time_End`, scan_log.`Time_Start`))))/60) as 'Total Man Hours',
"scan_log" as 'Data Process'
FROM
scan_log left join `user` on (`user`.last_name = scan_log.last_name)
inner join batch_log on (batch_log.job_number = scan_log.job_no)
group by
scan_log.`date`,
scan_log.last_name,
batch_log.`client`
union
SELECT
qc_log.`date`,
qc_log.last_name,
`user`.tl,
batch_log.`client`,
batch_log.`service`,
sum(qc_log.break_hours) as 'Total Break',
Hour(if (min(qc_log.time_start) <= '16:00' and max(qc_log.time_end) >= '16:00',
subtime(max(qc_log.time_end),'16:00'), if(min(qc_log.time_start)
and max(qc_log.time_end) <= '16:00', '0', subtime(max(qc_log.time_end),
min(qc_log.time_start))))) + minute(if (min(qc_log.time_start) <= '16:00' and max(qc_log.time_end) >= '16:00',
subtime(max(qc_log.time_end),'16:00'), if(min(qc_log.time_start)
and max(qc_log.time_end) <= '16:00', '0', subtime(max(qc_log.time_end),
min(qc_log.time_start)))))/60 as 'Over Time',
HOUR(subtime(SEC_TO_TIME(SUM(TIME_TO_SEC(SUBTIME(qc_log.time_end,qc_log.time_start)))),
if(min(qc_log.time_start) <= '16:00' and max(qc_log.time_end) >= '16:00',
subtime(max(qc_log.time_end),'16:00'), if(min(qc_log.time_start)
and max(qc_log.time_end) <= '16:00', '0', subtime(max(qc_log.time_end),
min(qc_log.time_start)))))) +
MINUTE(subtime(SEC_TO_TIME(SUM(TIME_TO_SEC(SUBTIME(qc_log.time_end,qc_log.time_start)))),
if(min(qc_log.time_start) <= '16:00' and max(qc_log.time_end) >= '16:00',
subtime(max(qc_log.time_end),'16:00'), if(min(qc_log.time_start)
and max(qc_log.time_end) <= '16:00', '0', subtime(max(qc_log.time_end),
min(qc_log.time_start))))))/60 as 'Regular Hours',
sum(Hour(IF(qc_log.`Time_End`<qc_log.`Time_Start`,
addtime('24:00:00', timediff(qc_log.`Time_End`, qc_log.`Time_Start`)),
timediff(qc_log.`Time_End`, qc_log.`Time_Start`)))) +
(sum(minute(IF(qc_log.`Time_End`<qc_log.`Time_Start`,
addtime('24:00:00', timediff(qc_log.`Time_End`, qc_log.`Time_Start`)),
timediff(qc_log.`Time_End`, qc_log.`Time_Start`))))/60) as 'Total Man Hours',
"qc_log" as 'Data Process'
FROM
qc_log
left join `user` on (`user`.last_name = qc_log.last_name)
inner join batch_log on (batch_log.job_number = qc_log.job_no)
where batch_log.total_batches is not null and qc_log.last_name = 'chua'
group by
qc_log.`date`,
qc_log.last_name,
batch_log.`client`
order by
`date` desc
Bookmarks