17,086
社区成员
发帖
与我相关
我的任务
分享
SELECT * FROM TEST T WHERE T.TRXN_DT=LAST_DAY(T.TRXN_DT) AND TO_CHAR(T.TRXN_DT,'MM') IN ('01','02','03')
with t as(
select to_date('2014/02/10','yyyy/mm/dd') tdate,1 id from dual
union all
select to_date('2014/02/15','yyyy/mm/dd') tdate,2 id from dual
union all
select to_date('2014/02/28','yyyy/mm/dd') tdate,3 id from dual
union all
select to_date('2014/03/10','yyyy/mm/dd') tdate,4 id from dual
)
select * from t where tdate in (select max(tdate)
from (select last_day(add_months(tdate, 0)) mm, id, tdate
from t
where tdate between to_date('2014/02/10', 'yyyy/mm/dd') and
to_date('2014/03/14', 'yyyy/mm/dd'))
group by mm)
select * from test t where t.trxn_dt=last_dt(t.trxn_dt) and t.trxn_dt between start_dt and t.end_dt