1. Learn
  2. /
  3. Courses
  4. /
  5. Hierarchical and Recursive Queries in SQL Server

Connected

Exercise

Calculate the sum of potencies

In this exercise, you will calculate the sum of potencies recursively. This mathematical series is defined as:

  • result=1 for step = 1
  • result + step^step for step > 1

The numbers in this series are getting large very quickly and the series does not converge. The task of this exercise is to calculate the sum of potencies for step = 9.

Instructions

100 XP
  • Define the CTE calculate_potencies with the fields step and result.
  • Initialize step and result using the definition of the mathematical series as a guide.
  • Add the next step to POWER(step + 1.. and add to result.