简体   繁体   English

关于SQL中数据model的这种层次结构有什么解决方案吗?

[英]Is there any solution about this hierarchical structure of data model in SQL?

I have this data model.我有这个数据 model。 This data model is about e-shop structure by categories.此数据 model 是关于按类别划分的网店结构。

在此处输入图像描述

item_category - every subcategory on website. item_category - 网站上的每个子类别。 item - every item on e-shop (item_category_id - every subcategory on website (leaf)). item - 电子商店上的每件商品(item_category_id - 网站上的每个子类别(叶子))。

parent_id is self-referent and define the hierarchical structure. parent_id 是自引用的并定义层次结构。 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 item_category_transitive_closure - 它是一个冗余数据结构,包含超类别-子类别关系的传递闭包,由 item_category 表上方的自引用父绑定表示

  • Every representation of a link between two categories is meaningful两个类别之间链接的每个表示都是有意义的
  • lies on the path to the root of the categories tree from the given category (#sub_cat_id) 0, M: 0, M位于从给定类别到类别树根的路径上 (#sub_cat_id) 0, M: 0, M
  • which are descendants of the category (#super_cat_id) within the category tree (0,M: 0,M)它们是类别树 (0,M: 0,M) 中类别 (#super_cat_id) 的后代

Target is "Count of items by main categories" in SQL.目标是 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.如果您查看此链接Get Root Node它应该向您展示如何获取 item_category 层次结构表中任何类别 ID 的根(主)类别。 Just join this result set to whatever query you write to be able to include the Main Category in it只需将此结果集加入到您编写的任何查询中,即可在其中包含主类别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM