Hello. I'm trying to retrieve the hours worked for each employee however i'm getting the total for the employee in a month.
Example:
Name Jan Feb Mar
---- --- --- ---
Joe 0 480 0
Tony 0 0 480
Sue 480 0 0
Output that I'm trying to get is (each employee worked 8hrs/day:
Name Jan Feb Mar
---- --- --- ---
Joe 160 160 160
Tony 160 160 160
Sue 160 160 160
Here are my tables:
tblemployee fields
-----------
employeeid
name
tblwork fields
-----------
workid
workdate
employeeid
tblhours fields
-----------
workid
hoursworked
SQL:
select tblemployee.name,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-1))) AS Jan,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-2))) AS FEb,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-3))) AS Mar,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-4))) AS Apr,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-5))) AS May
FROM (tblemployee INNER JOIN tblWork ON tblemployee.employeeid = tblWork.employeeid) INNER JOIN tblHours ON tblwork.workid = tblhours.workid
Group by tblemployee.name;
Example:
Name Jan Feb Mar
---- --- --- ---
Joe 0 480 0
Tony 0 0 480
Sue 480 0 0
Output that I'm trying to get is (each employee worked 8hrs/day:
Name Jan Feb Mar
---- --- --- ---
Joe 160 160 160
Tony 160 160 160
Sue 160 160 160
Here are my tables:
tblemployee fields
-----------
employeeid
name
tblwork fields
-----------
workid
workdate
employeeid
tblhours fields
-----------
workid
hoursworked
SQL:
select tblemployee.name,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-1))) AS Jan,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-2))) AS FEb,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-3))) AS Mar,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-4))) AS Apr,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-5))) AS May
FROM (tblemployee INNER JOIN tblWork ON tblemployee.employeeid = tblWork.employeeid) INNER JOIN tblHours ON tblwork.workid = tblhours.workid
Group by tblemployee.name;