我想了解有关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
我假设在某些情况下,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。如果只需要“描述”而不是其他文本属性,则可能必须基于属性类型进行过滤。
PS:我修改了您的查询以使用现代JOIN
语法。您不应该使用“逗号样式”联接,它们在1992年就过时了。
这似乎可行,并感谢语法更正!