Codeigniter active record select, left join, count

前端 未结 2 939
旧巷少年郎
旧巷少年郎 2021-01-15 17:57

I have a form that shows results from a database query, these results can have many other assets ajoined to them and I wanting to find a way of showing how many assets each

2条回答
  •  鱼传尺愫
    2021-01-15 18:46

    Not knowing your exact db setup, but something like this is how you would do this query using CodeIgniter's Active Record

     $this->db->select('places.place_id');
     $this->db->select_sum('places.place_id', 'total');
     $this->db->from('places');
     $this->db->join('users', 'places.place_id = user.place_id', 'left');
     $this->db->group_by('user.place_id');
     $this->db->get();
    

提交回复
热议问题