我有这样的模型
public function get_payment_method($date_from, $date_to){
$op_status = array('settlement','capture');
$this->db->select('op_payment_code,COUNT(order_id) as total,pc_caption');
$this->db->from("(dashboard_sales)");
$this->db->where('order_date BETWEEN "'. date('Y-m-d 00:00:00', strtotime($date_from)). '" and "'. date('Y-m-d 23:59:59', strtotime($date_to)).'"');
$this->db->where_in('op_status',$op_status);
$this->db->where('pc_caption is NOT NULL', NULL, FALSE);
$this->db->group_by('op_payment_code');
$query = $this->db->get();
return $query->result();
}
但是当我检查数据库时,order_id上的数据重复,如下所示,
问题是如何只在order_id计数一次?因此,如果存在相同的order_id,则将不计入
答案 0 :(得分:0)
您可以尝试以下操作:
$this->db->select('op_payment_code, COUNT(DISTINCT order_id) as total, pc_caption', false);