Kafamı product_count
sütununun nasıl çalıştığına dair etrafımı saran zor bir zaman geçiriyorum. Her nasılsa, her ikisi de catalog_category_entity
işaret eden see
ve e
takma adlarıyla kendini gösterir gibi görünüyor. Özellikle,MySQL: Kendinden Referanslı Oluşturulan Sütun (?) SELECT Sorgu
WHERE (see.entity_id = e.entity_id) OR (see.path LIKE CONCAT(e.path, '/%'))
Hem
see
ve e
masanın catalog_category_entity
rumuzudur. Bu ne yapıyor?
İşte tüm sorgu var:
SELECT `e`.*, `d_name`.`value` AS `name`, IF(s_name.value_id > 0, s_name.value, d_name.value) AS `name`, `d_is_active`.`value` AS `is_active`, IF(s_is_active.value_id > 0, s_is_active.value, d_is_active.value) AS `is_active`, `d_is_anchor`.`value` AS `is_anchor`, IF(s_is_anchor.value_id > 0, s_is_anchor.value, d_is_anchor.value) AS `is_anchor`,
(
SELECT COUNT(DISTINCT scp.product_id)
FROM `catalog_category_entity` AS `see`
LEFT JOIN `catalog_category_product` AS `scp`
ON see.entity_id=scp.category_id
WHERE (see.entity_id = e.entity_id) OR (see.path LIKE CONCAT(e.path, '/%'))
) AS `product_count`,
(
SELECT COUNT(cp.product_id)
FROM `catalog_category_product` AS `cp`
WHERE (cp.category_id = e.entity_id)
) AS `self_product_count`
FROM `catalog_category_entity` AS `e`
LEFT JOIN `catalog_category_entity_varchar` AS `d_name` ON d_name.entity_id=e.entity_id AND d_name.attribute_id=41 AND d_name.entity_type_id=e.entity_type_id AND d_name.store_id=0
LEFT JOIN `catalog_category_entity_varchar` AS `s_name` ON s_name.entity_id=e.entity_id AND s_name.attribute_id=41 AND s_name.entity_type_id=e.entity_type_id AND s_name.store_id=0
LEFT JOIN `catalog_category_entity_int` AS `d_is_active` ON d_is_active.entity_id=e.entity_id AND d_is_active.attribute_id=42 AND d_is_active.entity_type_id=e.entity_type_id AND d_is_active.store_id=0
LEFT JOIN `catalog_category_entity_int` AS `s_is_active` ON s_is_active.entity_id=e.entity_id AND s_is_active.attribute_id=42 AND s_is_active.entity_type_id=e.entity_type_id AND s_is_active.store_id=0
LEFT JOIN `catalog_category_entity_int` AS `d_is_anchor` ON d_is_anchor.entity_id=e.entity_id AND d_is_anchor.attribute_id=51 AND d_is_anchor.entity_type_id=e.entity_type_id AND d_is_anchor.store_id=0
LEFT JOIN `catalog_category_entity_int` AS `s_is_anchor` ON s_is_anchor.entity_id=e.entity_id AND s_is_anchor.attribute_id=51 AND s_is_anchor.entity_type_id=e.entity_type_id AND s_is_anchor.store_id=0
WHERE (`e`.`entity_type_id` = '3') AND (e.entity_id IN('24', '533')) ORDER BY LENGTH(e.path) ASC
bu belki de Gördüğüm en kendine ait sorgu. Bununla ne elde etmeye çalışıyorsun? Bahse girerim oraya varmanın çok daha iyi yolları var ...... –
Ürün sayımlarını, diğer birçok şeyin yanı sıra, “24” ve “533” kategorilerinde döndürürüm. Bunu ben yazmadım ve sadece 'product_count' sütununun WHERE' deyiminin nasıl çalıştığını merak ediyorum. – musicliftsme