We collect useful SQL queries, to help novice developers. Everything, that is connected with a database
-- Quantity Of Goods In Orders
-- DB_PREFIX
-- $product_id - Product ID
-- $this->config->get('config_complete_status_id') - Order Complete Status
SELECT COUNT(*) AS `total` FROM ' . DB_PREFIX . 'order_product op JOIN ' . DB_PREFIX . 'order o ON op.`order_id` = o.`order_id` WHERE op.product_id = ' . (int)$product_id . ' AND o.`order_status_id` = ' . (int)$this->config->get('config_complete_status_id') . ' GROUP BY o.`order_status_id`