我在下面有这个查询:
SELECT a.`reg_no`, b.`personnel_name`,
SUM(IF(month(a.`start_time`) = 1, ROUND(a.`act_hours`),0)) as 'Jan',
SUM(IF(month(a.`start_time`) = 2, ROUND(a.`act_hours`),0)) as 'Feb',
SUM(IF(month(a.`start_time`) = 3, ROUND(a.`act_hours`),0)) as 'Mar',
SUM(IF(month(a.`start_time`) = 4, ROUND(a.`act_hours`),0)) as 'Apr',
SUM(IF(month(a.`start_time`) = 5, ROUND(a.`act_hours`),0)) as 'May',
SUM(IF(month(a.`start_time`) = 6, ROUND(a.`act_hours`),0)) as 'Jun',
SUM(IF(month(a.`start_time`) = 7, ROUND(a.`act_hours`),0)) as 'Jul',
SUM(IF(month(a.`start_time`) = 8, ROUND(a.`act_hours`),0)) as 'Aug',
SUM(IF(month(a.`start_time`) = 9, ROUND(a.`act_hours`),0)) as 'Sept',
SUM(IF(month(a.`start_time`) = 10, ROUND(a.`act_hours`),0)) as 'Oct',
SUM(IF(month(a.`start_time`) = 11, ROUND(a.`act_hours`),0)) as 'Nov',
SUM(IF(month(a.`start_time`) = 12, ROUND(a.`act_hours`),0)) as 'Dec',
SUM('Jan' + 'Feb' + 'Mar' + 'Apr' + 'May' + 'Jun' + 'Jul' + 'Aug' + 'Sept' + 'Oct' + 'Nov' + 'Dec') / 12 as 'AVG',
a.`status_working`
FROM `daily_activity_control_card-man` AS a LEFT JOIN `personnel_master_data` AS b
ON a.`reg_no` = b.`reg_no` WHERE a.`status_working` = 'normal' AND YEAR(a.`start_time`) = '$_GET[df]'
GROUP BY `reg_no`
我需要在列的末尾获得AVG结果,从上面的查询中得到的结果为0.所有行在AVG列上都有0个值。 有人可以帮我吗?
我已经在Google上搜索了一些但没有运气。
感谢。