使用Mysql Query取得magento产品的销售数量,成本价格和产品售价

时间:2018-08-11 15:22:58

标签: php mysql magento-1.9

我想就我的问题寻求帮助。我有一个查询,其中它从数据库中提取数据(SKU,产品名称和产品说明)。我这样做的原因是我试图创建某种报告工具的扩展,尽管目前仅供个人使用。

我需要以下内容:

SKU, 产品名称, 产品说明, 售出数量 成本价格, 售价

那些粗体字,我已经设法将其从dbase本身中拉出。我想寻求任何协助以拉动剩余的3个。售出数量是该产品所有完整订单的总和。

这是我到目前为止设法使用的代码。

    SELECT 
    `e`.`sku`, 
    IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS `name`,
    IF(at_description.value_id > 0, at_description.value, at_description_default.value) AS `description`

FROM 
   `mgob_catalog_product_entity` AS `e` 
    INNER JOIN 
         `mgob_catalog_product_entity_varchar` AS `at_name_default` 
               ON (`at_name_default`.`entity_id` = `e`.`entity_id`) AND 
                  (`at_name_default`.`attribute_id` = (SELECT attribute_id FROM `mgob_eav_attribute` ea LEFT JOIN `mgob_eav_entity_type` et ON ea.entity_type_id = et.entity_type_id  WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND 
                  `at_name_default`.`store_id` = 0 
    LEFT JOIN 
          `mgob_catalog_product_entity_varchar` AS `at_name` 
               ON (`at_name`.`entity_id` = `e`.`entity_id`) AND 
                  (`at_name`.`attribute_id` = (SELECT attribute_id FROM `mgob_eav_attribute` ea LEFT JOIN `mgob_eav_entity_type` et ON ea.entity_type_id = et.entity_type_id  WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND 
                  (`at_name`.`store_id` = 1) 
    INNER JOIN 
         `mgob_catalog_product_entity_text` AS `at_description_default` 
               ON (`at_description_default`.`entity_id` = `e`.`entity_id`) AND 
                  (`at_description_default`.`attribute_id` = (SELECT attribute_id FROM `mgob_eav_attribute` ea LEFT JOIN `mgob_eav_entity_type` et ON ea.entity_type_id = et.entity_type_id  WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND 
                  `at_description_default`.`store_id` = 0 
    LEFT JOIN 
          `mgob_catalog_product_entity_text` AS `at_description` 
               ON (`at_description`.`entity_id` = `e`.`entity_id`) AND 
                  (`at_description`.`attribute_id` = (SELECT attribute_id FROM `mgob_eav_attribute` ea LEFT JOIN `mgob_eav_entity_type` et ON ea.entity_type_id = et.entity_type_id  WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND 
                  (`at_description`.`store_id` = 1) "

0 个答案:

没有答案