0

我在将下面的 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`

我已经按照这里的建议进行了尝试,但没有成功。

4

1 回答 1

0

你只需要检查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'); 

如有错误请报告

于 2013-03-29T16:31:55.883 回答