【发布时间】:2012-12-18 13:45:58
【问题描述】:
我正在使用 codeigniter。我想要一个 where 子句来获取 totalQuantity 小于 alterQuantity 的产品。我在 select 子句中使用 sum 来获取 totalQuantity。
$this->db->select("products.id as productid, products.code, products.name, products.unit, products.cost, products.price, sum(whs_products.quantity) as totalQuantity, products.alert_quantity as alertQuantity")
->from('products')
->where('alertQuantity <=', 'totalQuantity')
->join('whs_products', 'whs_products.product_id=products.id', 'left')
->group_by("products.id");
$this->db->get();
我不确定如何获得所需的产品 :( 编辑 如果尝试这个
->where('alertQuantity <=', 'totalQuantity')
我得到了所有产品,但 ->where('alertQuantity
【问题讨论】:
-
我想你想使用
HAVING,而不是WHERE。
标签: php mysql codeigniter join group-by