Created
September 5, 2014 10:35
-
-
Save ksomemo/ce589bdb0d172adc42e9 to your computer and use it in GitHub Desktop.
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
select | |
a.* | |
, ( | |
select | |
score | |
from test_table | |
where min <= diff | |
and max >= diff | |
) as s | |
, ( | |
select | |
rank | |
from test_table | |
where min <= diff | |
and max >= diff | |
) as r | |
from ( | |
select | |
a.* | |
, (julianday(Date('now')) - julianday(date(test_date))) as diff | |
from test_target a | |
) a | |
; | |
select | |
diff + 1 as hanuke | |
from ( | |
select | |
rank, min as diff, score | |
from test_table | |
union all | |
select | |
rank, max as diff, score | |
from test_table | |
order by rank | |
) | |
where (diff + 1) NOT IN ( | |
select | |
min as diff | |
from test_table | |
union all | |
select | |
max as diff | |
from test_table | |
) | |
and diff < ( | |
select max(max) | |
from test_table | |
) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment