Welcome Guest, Not a member yet? Register   Sign In
Mysql request problem
#1

Hello,
I can not solve the good qty in this request.
She always gives me double the value of qty.
The result is false when I put the following condition:

PHP Code:
$this->db->select_sum('qty_alert');
$this->db->join('stocks_alert''stocks_alert.id_product = stocks.id_product');
$this->db->having('qty < qty_alert'); 


Here is the complete request:

PHP Code:
$this->db->select('products.id, products.reference, products.label');
$this->db->select_sum('qty_alert');
$this->db->select("(SUM(CASE WHEN slug IN ('orders','variation','transfer','add') THEN stocks.qty ELSE 0 END) - SUM(CASE WHEN slug ='used' THEN stocks.qty ELSE 0 END)) as qty");
$this->db->from('products'); 
$this->db->join('stocks''stocks.id_product = products.id'); 
$this->db->join('stocks_alert''stocks_alert.id_product = stocks.id_product');
$this->db->group_start();
$this->db->like("products.reference"$_POST["search"]["value"]);  
$this
->db->or_like("products.label"$_POST["search"]["value"]);
$this->db->group_end();
$this->db->having('qty < qty_alert');
$this->db->group_by('products.id'); 

I also tried sub-query, but I can not do it.

Would anyone have an idea to put me on the track.
Thank you to all of you. 

Excuse me for my english.
Reply


Messages In This Thread
Mysql request problem - by alain - 02-13-2019, 12:32 AM
RE: Mysql request problem - by php_rocs - 02-13-2019, 09:21 PM
RE: Mysql request problem - by alain - 02-14-2019, 12:19 AM
RE: Mysql request problem - by php_rocs - 02-14-2019, 06:35 AM
RE: Mysql request problem - by alain - 03-20-2019, 11:44 PM
RE: Mysql request problem - by php_rocs - 03-21-2019, 02:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB