How to calculate the sum of values in a tree using SQL

后端 未结 9 2456
耶瑟儿~
耶瑟儿~ 2021-01-05 09:29

I need to sum points on each level earned by a tree of users. Level 1 is the sum of users\' points of the users 1 level below the user. Level 2 is the Level 1 points of the

9条回答
  •  孤街浪徒
    2021-01-05 10:05

    I would say: create a stored procedure, probably has the best performance. Or if you have a maximum number of levels, you could create subqueries, but they will have a very poort performance.

    (Or you could get MS SQL Server 2008 and get the new hierarchy functions... ;) )

提交回复
热议问题