Created
August 13, 2012 01:36
-
-
Save siosio/3336293 to your computer and use it in GitHub Desktop.
素数の時にJOJOと出力するSQL
This file contains 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
with nums as | |
( | |
select v1.col1 + (v2.col1 * 10) + 1 col1 | |
from | |
( | |
select 0 col1 from dual | |
union select 1 from dual | |
union select 2 from dual | |
union select 3 from dual | |
union select 4 from dual | |
union select 5 from dual | |
union select 6 from dual | |
union select 7 from dual | |
union select 8 from dual | |
union select 9 from dual | |
) v1, | |
( | |
select 0 col1 from dual | |
union select 1 from dual | |
union select 2 from dual | |
union select 3 from dual | |
union select 4 from dual | |
union select 5 from dual | |
union select 6 from dual | |
union select 7 from dual | |
union select 8 from dual | |
union select 9 from dual | |
) v2 | |
) | |
select case | |
when col1 = 1 then | |
to_char(col1) | |
when col1 = 2 then | |
'JOJO' | |
else | |
case | |
when ( | |
select min(mod(nums.col1, n2.col1)) | |
from nums n2 | |
where n2.col1 <= sqrt(nums.col1) | |
and n2.col1 >= 2 | |
) = 0 then | |
to_char(col1) | |
else | |
'JOJO' | |
end | |
end | |
from nums | |
order by col1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment