我有三张 table
买家
b_id 和 b_name
产品
p_id、p_status、p_cat
出价
bid_id、bid_amount、fkb_id、fkp_id(买家和产品表的外键)
买家可以对同一产品进行多次出价
我想获取 desc 中具有唯一 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)
最佳答案
在查询末尾使用分组依据...
$this->db->group_by('column_name');
关于mysql - 具有 join 和 order by 的多个 group_by,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41995412/