2017-02-02 100 views
0

我有三個表多個GROUP_BY與

買家

B_ID和b_name

產品

的p_id,p_status,p_cat

投標

bid_id加入和秩序,bid_amount,fkb_id,fkp_id(買方的外鍵和p RODUCT表)

買家可以做同類產品的出價次數
我想獲取每個產品具有遞減獨特BID_AMOUNT

我都嘗試這種

 $this->db->distinct(); 

    $this->db->from('bid'); 

    $this->db->join('product','product.p_id=bid.fkp_id'); 

    $this->db->join('buyer','buyer.b_id=bid.fkb_id'); 

    $this->db->where('product.p_status','close'); 

    $this->db->where('product.p_cat','diamond'); 

    $res = $this->db->get(); 

    $res_data = $res->result(); 

    return $res_data; 

此返回所有記錄產品但不是唯一的fkb_id(買方即在此情況下的投標人ID)

回答

0

在查詢結束時使用分組...

$this->db->group_by('column_name'); 
0

嘗試像這樣 $ this-> db-> max('bid_amount'); $ this-> db-> group_by('fkb_id');