【发布时间】:2011-12-11 17:15:34
【问题描述】:
我在同一张表中存储类别和子类别。如何计算所有子类别并更新我的父类别数据行。
categoryId sub cat id category_count subcategory_count 1 3 0 3 1 4 0 1 1 5 0 7 1 0 5 0我需要用子类别计数的总和来更新类别计数。
for eg;- 5 is my category count. I want my category count like this
5+ (3+7+1) so my category count should be 16
我怎样才能为此编写一个查询。
请帮帮我 谢谢
【问题讨论】:
-
如果你更新
category_count,下次运行查询时,它会再次将它们全部加起来,所以下次它会变成27,而不是16。这是故意的吗? -
@learner
category_count或subcategory_count是递归的吗? IE。你如何处理子子类别,子子子类别等......