SQL return a value at a specific date in time -
i'm trying find value @ date.
my data looks like
date value 2013-11-02 5 2013-10-10 8 2013-09-14 6 2013-08-15 4
how can determine value on 2013-09-30?
obviously answer 6 can't figure out sql code.
thanks
you can order by
, limiting number of rows. in sql server syntax (and sybase , access):
select top 1 t.* table t date <= '2013-09-30' order date desc;
in mysql (and postgres):
select t.* table t date <= '2013-09-30' order date desc limit 1;
in oracle:
select t.* (select t.* table t date <= '2013-09-30' order date desc ) t rownum = 1
edit:
and, sql standard way (should work in database):
select t.* table t date = (select max(date) table t2 date <= '2013-09-30' );
Comments
Post a Comment