【问题标题】:Magento SQL get product sku with the right active category in multishopsMagento SQL 在 multishops 中获取具有正确活动类别的产品 sku
【发布时间】:2018-11-26 09:44:22
【问题描述】:

我正在准备获取网站上显示的产品 sku 以及该产品的类别。

输出:

+-------------+------------+
| sku         | category_n |
+-------------+------------+
|      855202 |      test1 |
|     87972_k |      test2 |
|      887997 |      test1 |
+-------------+------------+

我看过这些表格:

catalog_category_product
catalog_product_entity
catalog_category_entity
catalog_category_entity_varchar

该查询只为一个 sku 返回了很多行,我得到了大约 100 条记录。我看不出哪一个是正确的类别,目前处于活动状态..

SELECT
    * 
FROM
    "catalog_category_product" as ccp 
JOIN
    "catalog_product_entity" as cpe ON "cpe.entity_id" = "ccp.product_id"
JOIN  
    "catalog_category_entity" as cat ON "cat.entity_id" = "ccp.category_id"
JOIN 
    "catalog_category_entity_varchar" as cv on cat.entity_id = cv."entity_id"

【问题讨论】:

  • 请提供一些示例数据

标签: sql magento magento-1.9


【解决方案1】:

假设您使用的是 mysql 数据库 尝试不要在对象名称(表和列名称)周围使用引号

SELECT * 
FROM catalog_category_product as ccp 
JOIN catalog_product_entity as cpe ON cpe.entity_id = ccp.product_id
JOIN catalog_category_entity as cat ON cat.entity_id = ccp.product_id
JOIN catalog_category_entity_varchar as cv on cat.entity_id = cv.entity_id

【讨论】:

  • 然后更新你的问题添加一个适当的数据样本..包含所有相关列的数据以及与数据样本一致的预期结果..(无论如何在mysql中使用双引号不起作用)
【解决方案2】:

您可以尝试使用左连接

SELECT
    * 
FROM
    "catalog_category_product" as ccp 
Left JOIN
    "catalog_product_entity" as cpe ON "cpe.entity_id" = "ccp.product_id"
Left JOIN  
    "catalog_category_entity" as cat ON "cat.entity_id" = "ccp.category_id"
Left JOIN 
    "catalog_category_entity_varchar" as cv on cat.entity_id = cv."entity_id"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-27
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多