Last active
August 29, 2015 14:07
-
-
Save MikeMKH/a5ca6668f5ef290ab507 to your computer and use it in GitHub Desktop.
Getting the values of 2 and 4 from an infinite sequence of numbers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(->> (range) (rest) (filter even?) (take 2)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE | |
@min AS INT = 0 | |
,@max AS INT = 100 | |
;WITH [range] AS ( | |
SELECT @min AS num | |
UNION ALL | |
SELECT num + 1 FROM [range] WHERE num < @max | |
) | |
SELECT TOP 2 * | |
FROM [range] | |
WHERE num > 0 | |
AND (num % 2) = 0 | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also my blog post http://comp-phil.blogspot.com/2014/09/how-to-get-2-and-4-or-learning-clojure.html
and SQL Fiddle http://sqlfiddle.com/#!6/aed15/10
which goes with this gist.