获得最小值但不是零(0)

时间:2013-08-27 07:06:27

标签: mysql codeigniter min

我希望使用Codeigniter从数据库中获取列的最小值但不是零。

这是我正在使用的当前代码,但它给了我0,因为列也有0值。

$this->db->select_min('saleprice');
        $this->db->join('category_products', 'category_products.product_id=products.id', 'right');
        $this->db->where('category_products.category_id', $cat_id);
        $this->db->where('products.enabled',1);
        return  $this->db->get('products')->row_array();

请让我知道如何获得最低价值但不是0

1 个答案:

答案 0 :(得分:3)

尝试添加where这样的条件

$this->db->where('saleprice >','0');

然后您的查询将变为

$this->db->select_min('saleprice');
$this->db->join('category_products', 'category_products.product_id=products.id', 'right');
$this->db->where('category_products.category_id', $cat_id);
$this->db->where('products.enabled',1);
$this->db->where('saleprice >','0');  //Add this 

您也可以使用!=之类的

$this->db->where('saleprice !=','0');     
相关问题