Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 右键加入zend2不工作_Mysql_Join_Zend Framework_Zend Framework2_Right Join - Fatal编程技术网

Mysql 右键加入zend2不工作

Mysql 右键加入zend2不工作,mysql,join,zend-framework,zend-framework2,right-join,Mysql,Join,Zend Framework,Zend Framework2,Right Join,我有一个查询,返回员工及其目标的属性,我想返回所有员工,不管他是否已经设定了目标。这是我的问题 $resultSet = $this->tableGateway->select(function (Select $select) use ($options) { $select->columns(array('*', new Expression("(SELECT CONCAT(employee.first_name, ' ', emp

我有一个查询,返回员工及其目标的属性,我想返回所有员工,不管他是否已经设定了目标。这是我的问题

 $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表,以便查询将返回所有员工,但当我尝试运行它时,只返回设置了目标的员工

备注:目标在os_表格中。
谢谢。

您可以使用joinLeft或joinRight来代替join?您好,我试过了,但不幸的是不起作用。谢谢为什么不管用?让我们看看你试过什么。您希望构建为字符串的最终请求是什么?