【问题标题】:Getting report of products through database query (EAV)通过数据库查询(EAV)获取产品报告
【发布时间】:2020-02-04 14:43:03
【问题描述】:

我正在尝试了解有关 EAV 的更多信息,并且正在对 magento 2 示例数据数据库进行一些测试。

我只想检索产品ID和产品描述,但catalog_product_entity表和catalog_product_entity_text表中的产品总数不匹配:

catalog_product_entity 表中有 2046 个产品:

如果我使用以下查询,我会得到 2052 个结果:

SELECT product.entity_id as "Description",description.value FROM catalog_product_entity_text description,catalog_product_entity product where product.entity_id = description.entity_id ORDER BY product.entity_id

【问题讨论】:

    标签: mysql magento magento2 entity-attribute-value


    【解决方案1】:

    我假设在少数情况下 entity_id 匹配文本表中的多行。或许可以有除描述以外的文本属性?

    试试这个:

    SELECT product.entity_id as Product_id,
      COUNT(*) AS count,
      GROUP_CONCAT(description.value) AS Description
    FROM catalog_product_entity_text description
    LEFT OUTER JOIN catalog_product_entity product ON product.entity_id = description.entity_id 
    GROUP BY product.entity_id
    ORDER BY product.entity_id
    

    我不熟悉 Magento 的 EAV 表,但我认为该表应该有一个用于属性标识符的列以及一个 entity_id。如果您只需要描述而不是其他文本属性,则可能必须根据属性类型进行过滤。

    P.S.:我调整了您的查询以使用现代 JOIN 语法。您不应该使用“逗号样式”连接,它们在 1992 年就已经过时了。

    【讨论】:

    • 这似乎有效,感谢语法更正!
    猜你喜欢
    • 2021-07-17
    • 2018-01-31
    • 2018-12-24
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 2018-04-17
    • 1970-01-01
    • 2018-04-13
    相关资源
    最近更新 更多