我正試圖讓totalQuantity小於alterQuantity的產品。我可以在where子句中使用select域中的somename作爲somename嗎?
$this->db
->select("products.id as productid, products.code as code, products.name, products.unit, products.price, sum(warehouses_products.quantity) as totalQuantity, products.alert_quantity as alertQuantity")
->from('products')
->where('alertQuantity >=', 'totalQuantity')
->join('warehouses_products', 'products.id=warehouses_products.product_id, 'left')
->group_by("products.id");
我得到的錯誤,在未知列'alertQuantity「where子句」如果我alertQuantity在where子句我得到未知列「totalQuantity」 products.alert_quantity「where子句」這一個我不知道如何改變,因爲這是數量的總和。你能幫我解決這個問題嗎?
我的問題: 我有選擇alert_quantity爲alertQuantity和金額(數量)爲totalQuantity
我可以使用alterQuantity和totalQuantity where子句中?
表結構
產品
ID,代碼,名稱,單元價格,alert_quantity
warehouses_products
ID,PRODUCT_ID,warehouse_id,數量
找到 我不能使用totalQuantity有沒有其他的想法,我怎麼能比較products.alert_quantity與sum(warehouses.products.quantity)?
您的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,以在'group_by products.id'附近使用正確的語法。ORDER BY(select product,'code','products'.'name','' – Saleem
在我的查詢中沒有在GROUP by Products.id之後的任何封閉括號,請粘貼整個查詢以及訂單條款 –
對不起,這是錯誤 - 'where子句'中的未知列'alertQuantity' select products.id as productid,products.code作爲代碼,products.name,products.unit,products.price,sum(warehouses_products.quantity)as totalQuantity,products.alert_quantity as alertQuantity from products LEFT join warehouses_products on products.id = warehouses_products.product_id where alertQuantity> = totalQuantity GROUP BY產品。編號 – Saleem