Created
October 6, 2011 15:54
-
-
Save sunaot/1267771 to your computer and use it in GitHub Desktop.
Haskell の groupBy の動作を誤解してるときに SQL で書いてみたそれっぽい動きをするもの
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
-- id num id+1 num | |
------------------------- | |
-- 1 1 2 2 | |
-- 2 2 3 3 | |
-- 3 3 4 4 | |
-- 4 4 5 5 | |
-- 5 5 6 6 | |
-- 6 6 7 7 | |
-- 7 7 8 8 | |
-- 8 8 9 9 | |
-- 9 9 | |
select | |
r1.id | |
, r1.num | |
, case | |
when (r1.num * r2.num) % 3 > 0 then 0 | |
else 1 | |
end as grp | |
from | |
recs r1 | |
left join | |
recs r2 | |
on (r1.id+1 = r2.id) | |
order by | |
r1.id | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment