如何将以下查询转换为codeigniter

时间:2014-07-15 11:43:43

标签: mysql codeigniter

SELECT r.report_id,
       a.advertisement_title,
       COUNT(r.advertisement_id) AS total
FROM report r
JOIN advertisement a ON a.advertisement_id = r.advertisement_id
GROUP BY r.advertisement_id

2 个答案:

答案 0 :(得分:1)

以下是如何做到的

$this->db->select('r.report_id,
       a.advertisement_title,
       COUNT(r.advertisement_id) AS total');
$this->db->from('report r');
$this->db->join('advertisement a','a.advertisement_id = r.advertisement_id');
$this->db->group_by('r.advertisement_id');

答案 1 :(得分:0)

$this->db->query('
SELECT r.report_id,
   a.advertisement_title,
   COUNT(r.advertisement_id) AS total
 FROM report r
JOIN advertisement a ON a.advertisement_id = r.advertisement_id
GROUP BY r.advertisement_id')