sql >> Database >  >> RDS >> Sqlserver

Recursieve functie in sql server 2005?

Zoek naar 'algemene tabeluitdrukkingen'. Zie ook deze link

Bijwerken Voorbeeld toevoegen van de link waarnaar hierboven wordt verwezen:

;WITH Fibonacci(n, f, f1)
AS (
        -- This is the anchor part
        -- Initialize level to 1 and set the first two values as per definition
        SELECT  CAST(1 AS BIGINT),
                CAST(0 AS BIGINT),
                CAST(1 AS BIGINT)

        UNION ALL

        -- This is the recursive part
        -- Calculate the next Fibonacci value using the previous two values
        -- Shift column (place) for the sum in order to accomodate the previous
        -- value too because next iteration need them both
        SELECT  n + 1,
                f + f1,
                f
        FROM    Fibonacci
        -- Stop at iteration 93 because we than have reached maximum limit
        -- for BIGINT in Microsoft SQL Server
        WHERE   n < 93
)
-- Now the easy presentation part
SELECT  n,
        f AS Number
FROM    Fibonacci


  1. LAAD DATA INFILE op externe machine

  2. Mysql inconsistent aantal rijen count(*) vs table.table_rows in information_schema

  3. Hoe een JSON-kolom op te vragen in MySQL

  4. wat is gematerialiseerde weergaven in orakel?