2015-11-08 63 views
1

我不明白为什么这个查询只提取1行,但必须有34000行。没有错误产生。 $ fromDate ='2015-10-01',$ toDate ='2015-10-31' and $ supervisorIdArray is flatten array。CodeIgniter查询楼

 $this->db->select('production.supervisor_id,production.employee_id,production.operation_id, SUM(production.quantity) as quantity,production_operation.operation_id,production_operation.rate'); 
     $this->db->from('production'); 
     $this->db->join('production_operation','production_operation.operation_id = production.operation_id', 'left'); 
     $this->db->where('production.production_date >=',$fromDate); 
     $this->db->where('production.production_date <=',$toDate); 
     $this->db->where_in('production.supervisor_id',$supervisorIdArray); 
     $this->db->order_by('production.supervisor_id','ASC'); 
     $this->db->order_by('production.employee_id','ASC'); 
     $this->db->order_by('production.operation_id','ASC');      
     $query = $this->db->get(); 
     $Rows = $query->num_rows(); 
+0

$ query的结果值是多少? – Tristan

+0

有多少个ID在$ supervisorIdArray –

+0

@ toby-allen最多451 –

回答

2

您正在使用组函数SUM因此它产生了一行。如果要多行添加group by

$this->db->group_by("production.supervisor_id"); 
+0

非常感谢您的解决方案。 –

+0

不用客气@HafsulMaru – Chayan