codeigniter active record nested query

前端 未结 1 1482
情歌与酒
情歌与酒 2021-01-28 01:02

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.* 
             


        
1条回答
  •  盖世英雄少女心
    2021-01-28 01:53

    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

    0 讨论(0)
提交回复
热议问题