繁体   English   中英

比较Codeigniter中两个表中的数据

[英]Compare data from two tables in codeigniter

我有两个表(Comment&Evaluation),我想对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子句中检查什么?

尝试运行以下代码:

$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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM