Calculate the sum of potencies
In this exercise, you will calculate the sum of potencies recursively. This mathematical series is defined as:
result=1forstep = 1result + step^stepforstep > 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.
Este ejercicio forma parte del curso
Hierarchical and Recursive Queries in SQL Server
Instrucciones del ejercicio
- Define the CTE
calculate_potencieswith the fieldsstepandresult. - Initialize
stepandresultusing the definition of the mathematical series as a guide. - Add the next step to
POWER(step + 1..and add toresult.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
-- Define the CTE calculate_potencies with the fields step and result
WITH ___ (___, ___) AS (
SELECT
-- Initialize step and result
___,
___
UNION ALL
SELECT
step + 1,
-- Add the POWER calculation to the result
___ + POWER(step + 1, ___ + 1)
FROM calculate_potencies
WHERE step < 9)
SELECT
step,
result
FROM calculate_potencies;