1

我有两个表(评论和评估),我想在 codeigniter 中执行以下 mySQL 查询。这是 mySQL 查询:

SELECT COUNT(DISTINCT source) AS NumberOfEvaluations 
FROM COMMENT , EVALUATION
WHERE evaluation_id = EVALUATION.id AND EVALUATION.department_id = '$department_id' ;

这是我到达的更近的地方:

$this->db->select('count(DISTINCT(source))');  
$this->db->from('comment','evaluation');  

$this->db->where();  

$query=$this->db->get();  
return $query->num_rows();  

我的问题是我应该在 codeigniter 的 where 子句中检查什么?

4

1 回答 1

0

尝试运行此代码:

$this->db->select('count(DISTINCT(source))');  
$this->db->from('comment c','evaluation e');  

$this->db->where('c.evaluation_id','e.id');
$this->db->where('e.department_id', $department_id);
于 2013-05-23T20:04:29.010 回答