codeigniter active record nested query

為{幸葍}努か 提交于 2019-12-20 05:37:33

问题


I'm having a problem converting below MySQL code to a Codeigniter active record query.

SELECT sss.*, c.country_name, c.country_code 
  FROM ( SELECT gr.* 
           FROM (`be_goldrate` as `gr`) 
          WHERE `gr`.`country_id` != 0 
            AND `gr`.`rate_type` = 'calculated' 
           ORDER BY gr.date DESC ) as sss 
   LEFT JOIN `be_countries` as `c` 
     ON `c`.`country_id`=`sss`.`country_id`  
   GROUP BY `sss`.`country_id`

I've tried as suggested here but without success.


回答1:


you just need to check the Codeigniter Documentation

     $this->db->select('sss.*, c.country_name, c.country_code ');
       $this->db->from('(SELECT gr.* 
       FROM (`be_goldrate` as `gr`) 
      WHERE `gr`.`country_id` != 0 
        AND `gr`.`rate_type` = "calculated" 
       ORDER BY gr.date DESC) as sss');
       $this->db->join('be_countries as c','c.country_id = sss.country_id','left');

       $this->db->group_by('sss.country_id'); 

please report if any error



来源:https://stackoverflow.com/questions/15703992/codeigniter-active-record-nested-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!