Hello! I'm currently working on a time sheet application where I'm recording activities and corresponding total number of hours.
I need to group the activities by type and obtain the corresponding costs. To calculate the cost, the number of hours spent by an employee is multiplied by the rate per hour.
The rate per hour is calculated by using the monthly salary.
For the moment if I group my data by users, I correctly obtain the activities with the corresponding costs.
However, I would like to remove that group by employee clause and group by activities only. And obviously, obtain the correct costs amount.
My current query is as follows:
CONCAT(Title,' ',FirstName,' ',Surname) as Employee,
ACTIVITYTYPE as ActivityType,
TIMESHEETDATA.ACTID as Activity,
SUM(TIME_MON+TIME_TUE+TIME_WED+TIME_THU+TIME_FRI+TIME_SAT+TIME_SUN) as TotalHours,
TRUNCATE(SUM(TIME_MON+TIME_TUE+TIME_WED+TIME_THU+TIME_FRI+TIME_SAT+TIME_SUN)*((BILLINGAMT/20)/9),2) as TotalCost
FROM TIMESHEETDATE INNER JOIN USERDET ON 1=1 INNER JOIN BILLINGDETID ON USERDET.BILLINGID=BILLINGDETID.BILLID
INNER JOIN TIMESHEETDATA ON TIMESHEETDATA.WEEKID=TIMESHEETDATE.WEEKID AND TIMESHEETDATA.LOGINID=USERDET.LOGINID
INNER JOIN ACTIVITYDET ON ACTIVITYDET.ActivityDesc=TIMESHEETDATA.ACTID
INNER JOIN pmuser ON pmuser.BELOWID=timesheetdata.LOGINID WHERE RECSTATUS='APPROVED'
GROUP BY ACTIVITYTYPE,TIMESHEETDATA.ACTID,USERDET.LOGINID