従業員の属性とその目的を返すクエリがあります。私が望むのは、従業員の目的が既に設定されているかどうかに関係なく、すべての従業員を返すことです。これは私のクエリです
$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;
私のクエリに従って、クエリがすべての従業員を返すように従業員テーブルを右結合しようとしましたが、実行しようとすると、目的が設定されている従業員のみが返されます。
PS。目的は os_form テーブルにあります。ありがとう。