Hello. There is such a request
SELECT pay16_products.*, (SUM(pay16_orders.seller_summ) + SUM(pay16_orders.partner_summ)) / COUNT(DISTINCT pay16_visits.id) AS orders_summ, COUNT(DISTINCT pay16_orders.id) AS count_orders, COUNT(DISTINCT pay16_visits.id) AS count_visits, COUNT(DISTINCT pay16_orders.id) / COUNT(DISTINCT pay16_visits.id) * 100 AS conversion, (SUM(pay16_orders.seller_summ) + SUM(pay16_orders.partner_summ)) / COUNT(DISTINCT pay16_visits.id) / COUNT(DISTINCT pay16_visits.id) AS cpc FROM `pay16_products` LEFT JOIN `pay16_orders` ON `pay16_orders`.`product_parent_id` = `pay16_products`.`id` AND `pay16_orders`.`status` = 1 LEFT JOIN `pay16_product_visits` AS `pay16_visits` ON `pay16_visits`.`product_parent_id` = `pay16_products`.`id` WHERE `pay16_products`.`active` = 1 AND `pay16_products`.`active_partners_system` = 1 AND `pay16_products`.`parent_id` IS NULL GROUP BY `pay16_products`.`id` The problem is that its execution time is critically high. The tables have up to 150k records.
In requests I am not an ace and I will be very grateful to you for any help. Thank!
What is required from the request: extract the amount of orders (from orders), number of unique visitors (from visits), conversion (by formula), click price (by formula) - all this is calculated for each product (products table).
Table relations: orders (parent_product_id, product_id) table x products (id) table visits (parent_product_id, product_id) table x products (id) table
pay16_products.idis never UNIQUE ... - Akina