【发布时间】:2018-01-31 09:06:16
【问题描述】:
为了对 magento 中的销售数据进行市场购物篮分析,我需要从 magento 检索每张发票中包含的产品。到目前为止,这就是我得到的。
SELECT
tblInvoice.increment_id AS orderId,
tblLine.product_id AS productId,
tblLine.sku as productSku,
tblLine.qty as qty
FROM
sales_flat_invoice AS tblInvoice
RIGHT JOIN
sales_flat_invoice_item AS tblLine
ON tblInvoice.entity_id = tblLine.parent_id
但是,问题在于,对于同时包含可配置产品和简单产品的产品,我得到了两者。如果它是单独的,我只需要简单的产品。
orderId productId productSku qty
100000004 456 mpd00338 1.0000 <-- The simple product in this pair should be removed
100000004 476 mpd00338 1.0000 <-- The simple product in this pair should be removed
100000006 374 abl004 4.0000 <-- This simple product is alone, and should therefore stay
100000006 417 wbk002 1.0000 <-- Once again the simple product in this pair should be removed
100000006 284 wbk002 1.0000 <-- Once again the simple product in this pair should be removed
我最初的想法是使用可见性来删除冗余实体,但我不确定这是否适用于所有情况,或者是否可能存在两者都可见或隐藏的情况?
所以我的问题是
我应该如何更改我的 sql 语句以便在可配置产品的情况下仅选择一种产品(而不删除那些独立的简单产品?
此解决方案是否适用于 1.7、1.8 和 1.9 版本?
是否存在解决方案不起作用的情况?
注意。对于分组产品和捆绑产品,我当然应该得到所有简单的产品,因为它们实际上代表了一个真实的产品。
【问题讨论】:
标签: php sql magento magento-1.9 business-intelligence