我有一个查询,它返回员工的属性及其目标,我想要的是返回所有员工,无论他们的目标是否已经设定。这是我的查询
$resultSet = $this->tableGateway->select(function (Select $select) use ($options) {
$select->columns(array('*',
new Expression("(SELECT CONCAT(employee.first_name, ' ', employee.last_name)
FROM employee
WHERE id = CAST(os_form.created_by AS CHAR)) as created_by"),
new Expression("SUM(CASE WHEN os_form_objective.type = 1 THEN objective.result * objective.weight / 100 END) * os_event.business_weight / 100 as business_result"),
new Expression("SUM(CASE WHEN os_form_objective.type = 2 THEN objective.result * objective.weight / 100 END) * os_event.team_weight / 100 as team_result"),
new Expression("SUM(CASE WHEN os_form_objective.type = 3 THEN objective.result * objective.weight / 100 END) * os_event.individual_weight / 100 as individual_result"),
));
$select->join('os_event',
'os_form.os_event_id = os_event.id',
array('business_weight', 'team_weight', 'individual_weight'))
->join('business_line',
'os_form.business_line_id = business_line.id',
array('business_line' => 'name'))
->join('unit',
'os_form.unit_id = unit.id',
array('unit' => 'name'))
->join('sub_unit',
'os_form.sub_unit_id = sub_unit.id',
array('sub_unit' => 'name'))
->join('employee',
'os_form.employee_id = employee.id',
array('first_name', 'middle_name', 'last_name', 'date_started', 'role'),
Select::JOIN_RIGHT)
->join('os_form_objective',
'os_form.os_event_id = os_form_objective.os_event_id AND os_form.employee_id = os_form_objective.employee_id AND os_form.sub_unit_id = os_form_objective.sub_unit_id AND os_form.role = os_form_objective.role',
array())
->join('objective',
'os_form_objective.objective_id = objective.id',
array());
$select->group(array('os_form.os_event_id', 'os_form.employee_id', 'os_form.sub_unit_id'));
if (!empty($options)) {
$select->where($options);
//$select->Where("employee.first_name LIKE ?", '%'.$name.'%');
}
// \Zend\Debug\Debug::dump($select);
});
return $resultSet;
根据我的查询,我试图加入employee表,以便查询将返回所有员工,但是当我尝试运行它时,只返回那些设置了目标的人。
PS。目标在os_form表中。 感谢。