Relative Content

Tag Archive for phpsqllaravel

column not found but column exists in laravel query

Below is my query in laravel project.In this query purchase_return_products.purchase amount actually exists but this show error ‘[2024-07-14 16:28:02] local.ERROR: Errors: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘purchase_return_products.purchase_amount’ in ‘field list’ (Connection: mysql, SQL: select count(*) as aggregate from (select IFNULL(SUM(purchase_products.quantity), 0) as purchase_quantity, IFNULL(SUM(purchase_products.purchase_amount), 0) as purchase_amount, purchase_products.product_id, IFNULL(SUM(sale_products.quantity), 0) as sale_quantity, IFNULL(SUM(sale_products.sale_purchase_amount), 0) as sale_purchase_amount, IFNULL(SUM(purchase_return_products.quantity), 0) as purchase_return_quantity, IFNULL(SUM(purchase_return_products.purchase_amount), 0) as purchase_return_amount from products left join (SELECT product_id, SUM(purchase_products.quantity) as quantity, SUM(purchase_products.purchase_amount) as purchase_amount FROM purchase_products GROUP BY product_id) as purchase_products on purchase_products.product_id = products.identity left join (SELECT product_id, SUM(sale_products.quantity) as quantity, SUM(sale_products.sale_purchase_amount) as sale_purchase_amount FROM sale_products GROUP BY product_id) as sale_products on sale_products.product_id = products.identity left join (SELECT product_id, SUM(purchase_return_products.quantity) as quantity, SUM(purchase_return_products.purchase_amount) as purchase_return_amount FROM purchase_return_products GROUP BY product_id) as purchase_return_products on purchase_return_products.product_id = products.identity where products.store_id = 2024061225851482 group by purchase_products.product_id having (purchase_quantity – (purchase_return_quantity + sale_quantity)) > 0) as aggregate_table)’.Please help me solving this problem.