Make this query to more simple

by Arnie Mallari   Last Updated April 15, 2019 11:26 AM - source

I have this query that will connect to my database. I encountered it's too slow to load the data that i want.

SELECT
IFNULL((SELECT SUM(c.due_to_office) AS dt_amount FROM sales_entry_summary a, sales_products b, sales_entry c WHERE a.ses_id = c.ses_id AND a.sales_date = '2019-01-01' AND a.`status` = 'AUDITED' AND a.product_id = b.product_id AND b.so_category = 'DT'),0) AS dt_amounts,
IFNULL((SELECT SUM(c.due_to_office) AS rt_amount FROM sales_entry_summary a, sales_products b, sales_entry c WHERE a.ses_id = c.ses_id AND a.sales_date = '2019-01-01' AND a.`status` = 'AUDITED' AND a.product_id = b.product_id AND b.so_category = 'RT'),0) AS rt_amounts,
IFNULL((SELECT SUM(c.due_to_office) AS it_amount FROM sales_entry_summary a, sales_products b, sales_entry c WHERE a.ses_id = c.ses_id AND a.sales_date = '2019-01-01' AND a.`status` = 'AUDITED' AND a.product_id = b.product_id AND b.so_category = 'IT'),0) AS it_amounts,
IFNULL((SELECT SUM(c.due_to_office) AS lr_amount FROM sales_entry_summary a, sales_products b, sales_entry c WHERE a.ses_id = c.ses_id AND a.sales_date = '2019-01-01' AND a.`status` = 'AUDITED' AND a.product_id = b.product_id AND b.so_category = 'LR'),0) AS lr_amounts,
IFNULL((SELECT SUM(c.due_to_office) AS ir_amount FROM sales_entry_summary a, sales_products b, sales_entry c WHERE a.ses_id = c.ses_id AND a.sales_date = '2019-01-01' AND a.`status` = 'AUDITED' AND a.product_id = b.product_id AND b.so_category = 'IR'),0) AS ir_amounts,
IFNULL((SELECT SUM(c.due_to_office) AS v_amount FROM sales_entry_summary a, sales_products b, sales_entry c WHERE a.ses_id = c.ses_id AND a.sales_date = '2019-01-01' AND a.`status` = 'AUDITED' AND a.product_id = b.product_id AND b.so_category = 'V'),0) AS v_amounts;
Tags : php mysql sql


Related Questions





Mysql Can't create/write to file error#13

Updated April 16, 2018 11:26 AM