编码器活动记录嵌套查询



我有一个问题下面MySQL代码转换为Codeigniter活动记录查询。

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`
我已经按照这里的建议试过了,但没有成功。

你只需要查看Codeigniter文档

     $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'); 

如果有错误请报告

相关内容

  • 没有找到相关文章

最新更新