这是我的数据库: 我想按出价金额和产品ID的最大值对行进行排序。
我的代码使用Codeigniter或PHP:
$product_id=$data;
unset($data['product_id']);
$win= "SELECT user_id FROM bid_products WHERE product_id like '$product_id' and MAX(bid_amount)";
$winner=$this->db->query($win);
$user_id =$winner['user_id'];
或
this->db->select('user_id');
$this->db->from('bid_products');
$this->db->where('product_id',$product_id);
$query=$this->db->get();
return $query;
答案 0 :(得分:0)
假设不存在相同bid_amount且出价总是在增加的可能性,则此查询应该完成此任务:
SELECT user_id
FROM bid_products
WHERE product_id = '$product_id'
ORDER BY bid_amount DESC
LIMIT 1;