根据一个查询日期,求这个日期的月初第一天和月末最后一天
要放到where 条件后的 日期字段 between and
这样,应该怎么写?
------解决思路----------------------
先求本月的一号,然后在求下个月的一号,在用下个月一号减一就是本月的最后一天,sql:
select to_date(to_char(aa.dt,'yyyymm')
------解决思路----------------------
'01','yyyymmdd') as a,
to_date(to_char(add_months(aa.dt,1),'yyyymm')
------解决思路----------------------
'01','yyyymmdd')-1 as b from aaaa
------解决思路----------------------
select *
from emp a
where a.hiredate
between add_months(trunc(last_day(sysdate) + 1), -1)
--月初 (先得到本月最后一天,加一天是下月第一天,减去一月是本月第一天)
and trunc(last_day(sysdate)) --本月最后一天