We recently reviewed recursive SQL and I wrote a query which will return the numbers in the Fibonacci sequence which are less than 100. (This is for DB2)

With FIBONACCI (FRST, SCND) AS

(SELECT 1, 1 FROM SYSIBM.SYSDUMMY1

 UNION ALL 

 SELECT SCND, FRST + SCND 

 FROM FIBONACCI

 WHERE SCND < 100  )   SELECT FRST FROM FIBONACCI; [/sourcecode] The source code here was placed in here using a shortcode as pointed out here.

Advertisements