1

我需要比较同一个 mysql magento 表中的记录。有没有办法通过比较 url_key 和 url 来比较同一张表中的 2 条记录?我在下面发布了与我正在寻找的内容相对应的信息。

我希望这也能帮助其他在 Magento 数据库上工作的人,因为我已经发布了我之前的 2 个关于我如何比较 2 个 mysql 表以确保为 magento 中的类别创建记录的查询。我发现如果 url-keys 和 url 不匹配,Magento 将无法运行平面文件重新索引。我进行了一些检查,以确保我的 url 在我的 catalog_category_entity_varchar 表和 core_url_rewrite 表中都是正确的。我最初跑了:

SELECT * FROM catalog_category_entity_varcharc2t WHERE NOT EXISTS (SELECT * FROM core_url_rewritec WHERE c.category_id = c2t.entity_id)

确保我们所有的类别也都输入 core_url 重写。然后我运行另一个查询以确保两个表中的所有 url 都匹配:

SELECT * FROM core_url_rewritec WHERE 不存在(SELECT * FROM catalog_category_entity_varcharc2t WHERE c2t. entity_id= c. category_id AND c2t. value= c. request_path

现在我想再运行一个查询,以确保 catalog_category_entity_varchar 上的 url 也与其对应的 url 键正确,但我完全坚持它并且不知道如何编写语句。

基本上 catalog_category_entity_varchar 表如下所示:

catalog_category_entity_varchar:

记录 1:
value_id:68
entity_type_id:3
attribute_id:43
store_id:0
entity_id:10
value:shop-by

记录2:
value_id:73
entity_type_id:3
attribute_id:57
store_id:0
entity_id:10
value:shop-by.html

两条记录的 entity_id 均为 10。url_key 的属性 ID 是 43,而 url ID 是 57。我想这些是我需要用来识别我正在比较的内容。

所以基本上我需要运行一个查询,将实体 id 相互匹配,然后将 url-key 与 url itslef 进行比较,以确保它包含 url 键。它必须去除 .html 以及 url 代码的任何其他部分,因为比第一级更深的记录看起来像 catalog/shirts/shop-by.html。

记录 3:
value_id:637
entity_type_id:3
attribute_id:57
store_id:0
entity_id:88
value:catalog/shirts/shop-by.html

此外,还有一些记录也包含此 URL-Key,但我假设由于查询将基于它的主键 (entity_id),我们不必担心这一点。

如果我没有以正确的格式写这篇文章,我深表歉意,因为我还是这个论坛的新手。我提前感谢您的帮助。如果有任何不清楚或需要更多信息,请告诉我。

4

1 回答 1

2

检查这个查询,它有点难看,但据我所知它有效。

SELECT `t1`.*, `t2`.`value` AS `url_path`
FROM `catalog_category_entity_varchar` AS `t1`
LEFT JOIN (
    SELECT `catalog_category_entity_varchar`.`value`,
        `catalog_category_entity_varchar`.`entity_id`,
        `catalog_category_entity_varchar`.`attribute_id`
    FROM `catalog_category_entity_varchar`
) AS `t2`
ON `t1`.`entity_id`=`t2`.`entity_id`
WHERE `t1`.`attribute_id` = 43
AND `t2`.`attribute_id` = 57
AND `t1`.`value` != `t2`.`value`
于 2013-08-17T00:02:15.333 回答