$where['enterprise_id'] = $enterpriseId; //企业名称不为空 if(!empty($enterpriseName)){ $where['enterprise_name'] = array('like',"%$enterpriseName%"); } $table2 = array('enterprise_data.yunkh_enterprise_rel_enterprise'=>'ed_ere', 'enterprise_data.yunkh_enterprise_info'=>'ed_ei'); $where2 = array('ed_ere.enterprise_id'=>$enterpriseId, 'status'=>'1', 'ed_ei.enterprise_name'=>array('like',"%$enterpriseName%"), '_string'=>'ed_ere.rel_enterprise_id = ed_ei.enterprise_id'); $contractInfoList = $this->model->field('enterprise_id,enterprise_name') ->table(array('enterprise_data.yunkh_enterprise_info' => 'ed_id')) ->where($where) ->union(array('field'=>'ed_ei.enterprise_id,enterprise_name','table'=>$table2,'where'=>$where2),true) ->select(); return $contractInfoList; 执行的sql: SELECT 'enterprise_id','enterprise_name' FROM enterprise_data.yunkh_enterprise_info 'ed_id' WHERE 'enterprise_id' = 1 AND 'enterprise_name' LIKE '%农%' UNION ALL SELECT ed_ei.enterprise_id,'enterprise_name' FROM enterprise_data.yunkh_enterprise_rel_enterprise 'ed_ere',enterprise_data.yunkh_enterprise_info 'ed_ei' WHERE ed_ere.enterprise_id = 1 AND 'status' = '1' AND ed_ei.enterprise_name LIKE '%农%' AND ( ed_ere.rel_enterprise_id = ed_ei.enterprise_id )
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。