子树 SQL 嵌套集的乘积计数
请参阅http://mikehillyer.com/articles/managing-hierarchical-data- in-mysql/
在“嵌套集中的聚合函数”标题下,
我试图制定一个类似于给定示例的查询,但我希望它在子树级别工作,所以如果我查询 MP3 播放器我会得到如下结果集:
|NAME |COUNT|
----------------------
|MP3 PLAYERS | 2 | // 2 because 1 at this level and 1 at child level
|FLASH PLAYERS | 1 |
See http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/
Under the heading "Aggregate Functions in a Nested Set"
I'm trying to work out a query similar to the example given, except I want it to work at a sub-tree level, so if I queried for MP3 players I would get a result set like;
|NAME |COUNT|
----------------------
|MP3 PLAYERS | 2 | // 2 because 1 at this level and 1 at child level
|FLASH PLAYERS | 1 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设自引用表 tree_node 创建如下:
可以使用以下 SQL 检索计数:
Assuming the self referencing table tree_node is created as follows:
The counts can be retrieved with the following SQL: