I'm trying to get some data from my SQL database but I have some issue that I don't understand. This is my query :
SELECT SUM(t0_.in_budget_hours) AS sclr_0,
SUM(t0_.billable_amount) AS sclr_1,
SUM(t0_.out_budget_hours) AS sclr_2,
SUM(t0_.unprod_hours) AS sclr_3,
SUM(t0_.off_hours) AS sclr_4,
SUM(t0_.duration) AS sclr_5,
SUM(t0_.in_budget_hours) / SUM(t0_.duration) * 100 AS sclr_6,
CONCAT(c1_.name, ' ', c1_.lastname) AS sclr_7,
c1_.alias AS alias_8,
c1_.email AS email_9
FROM collaborator c1_
RIGHT JOIN timesheet t0_ ON (c1_.email = t0_.email)
WHERE t0_.entry_date BETWEEN '2020-01-01 00:00:00' AND '2020-01-22 23:59:59'
GROUP BY sclr_7, c1_.alias, c1_.email
ORDER BY sclr_7 ASC
I have a lot of information calculated from timesheet table and I would like to merge these calcul with the collaborator name.
I would like to have All collaborators and join them with timesheets, even if they don't have any timesheet (LEFT JOIN). If there is no row related to the collaborator, the sum result should be 0 but the collaborator should appear in result dataset. But currently If the collaborator do not have any timesheet BETWEEN '2020-01-01 00:00:00' AND '2020-01-22 23:59:59'
, he will not appear in results.
I tryied several type of join using this thread What's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN? but nothing worked for me. Can someone tell me how to have all collaborator even if there is no timesheet ?