是否可以比较同一个表中的 2 条记录?我已经使用比较了两个表以确保我的记录准确
SELECT *
FROM `catalog_category_entity_varchar` c2t
WHERE NOT EXISTS (
SELECT *
FROM `core_url_rewrite` c
WHERE c.category_id = c2t.entity_id
)
现在我尝试比较catalog_category_entity_varchar 中的记录是否存在任何不一致之处。这是我的两条记录的示例。
catalog_category_entity_varchar:
记录1:
value_id: 68
实体类型 ID: 3
attribute_id: 43
store_id: 0
实体ID: 10
值: 购物依据
记录2:
value_id: 73
实体类型 ID: 3
attribute_id: 57
store_id: 0
实体ID: 10
值: shop-by.html
entity_id 是唯一标识符。我必须将 url 键的值(attribute_id = 43)与 url 键的值(attribute_id 57)进行比较。我假设我必须在之后使用通配符 %,这将删除 .html,在之前使用另一个通配符,这将删除部分任何 2 级以上类别 url 上的 url(例如catalog/shirts/shop-by.html)。
如果这样可以更轻松地复制表和初始比较语句,我只需要知道如何修改查询以匹配属性 ID 并使用通配符。
最佳答案
我不确定这是否能完成您想做的所有事情,但我认为这可能是朝着正确方向迈出的一步。它将比较属性 43 的记录和属性 57 的记录,看看 43 记录的值字段是否不在 57 记录的值字段中。
SELECT *
FROM catalog_category_entity_varchar t1
JOIN catalog_category_entity_varchar t2
ON t1.entity_id = t2.entity_id
AND t2.attribute_id = 57
WHERE t1.attribute_id = 43
AND INSTR(t2.value, t1.value) = 0;
关于mysql - 如何比较同一个 MySQL 表中的 2 条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18283238/