I have this data model. This data model is about e-shop structure by categories.
item_category - every subcategory on website. item - every item on e-shop (item_category_id - every subcategory on website (leaf)).
parent_id is self-referent and define the hierarchical structure. Roots of hierarchical structure mean main categories.
item_category_transitive_closure - it is a redundant data structure containing a transitive closure of the supercategory-subcategory relation, which is represented by the self-reference parent binding above the item_category table
Target is "Count of items by main categories" in SQL.
Thank you for your help
if you look at this link Get Root Node it should show you how to get the root (main) category for any category ID in your item_category hierarchy table. Just join this result set to whatever query you write to be able to include the Main Category in it
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.