Skip to content

Instantly share code, notes, and snippets.

@ksomemo
Created September 5, 2014 10:35
Show Gist options
  • Save ksomemo/ce589bdb0d172adc42e9 to your computer and use it in GitHub Desktop.
Save ksomemo/ce589bdb0d172adc42e9 to your computer and use it in GitHub Desktop.
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