select max(字段) from A where to_date(substr(changetime,1,8),'yyyy-mm-dd')<=to_date('20080930','yyyy-mm-dd')
select max(changetime) from (select changetime from A where changetime>'20080900000000') t;
select max(changetime) from A where changetime>'20080900000000'
select max(changetime) from A where substr(changetime,1,8)<=20080930
SQL> select * from t;CHANGETIME NUM ------------------------------------------------------------ --------------------------------------- 20080901121121 12 20080801121121 24 20080701121121 30 20080601121121 60 20081001121121 90SQL> SQL> select changetime,max(num) num from t 2 where to_date(substr(changetime,1,6),'yyyymm')<=to_date('200809','yyyymm') 3 group by changetime order by num desc;CHANGETIME NUM ------------------------------------------------------------ ---------- 20080601121121 60 20080701121121 30 20080801121121 24 20080901121121 12SQL> SQL> select * from ( 2 select changetime,max(num) num from t 3 where to_date(substr(changetime,1,6),'yyyymm')<=to_date('200809','yyyymm') 4 group by changetime 5 ) A where rownum=1 order by num;CHANGETIME NUM ------------------------------------------------------------ ---------- 20080601121121 60SQL>
select max(字段) from A where to_date(substr(changetime,1,8),'yyyy-mm-dd') <=to_date('20080930','yyyy-mm-dd')
SQL> select * from t;CHANGETIME NUM
------------------------------------------------------------ ---------------------------------------
20080901121121 12
20080801121121 24
20080701121121 30
20080601121121 60
20081001121121 90SQL>
SQL> select changetime,max(num) num from t
2 where to_date(substr(changetime,1,6),'yyyymm')<=to_date('200809','yyyymm')
3 group by changetime order by num desc;CHANGETIME NUM
------------------------------------------------------------ ----------
20080601121121 60
20080701121121 30
20080801121121 24
20080901121121 12SQL>
SQL> select * from (
2 select changetime,max(num) num from t
3 where to_date(substr(changetime,1,6),'yyyymm')<=to_date('200809','yyyymm')
4 group by changetime
5 ) A where rownum=1 order by num;CHANGETIME NUM
------------------------------------------------------------ ----------
20080601121121 60SQL>