从一年的开始到一个月前的最后一天结束之间的日期?

时间:2013-10-04 05:16:37

标签: sql oracle

我的查询有问题。我不知道如何计算日期数据。我想显示从早月到一个月的日期。

例如,今年。从jan-sept。本月不包括在内。我对这种情况有疑问

and mhn.trh_masuk between add_months(Last_day(sysdate) + 1, -10) and add_months(Last_day(sysdate) + 0, -2)

这是我的oracle sql:

select DISTINCT
count(mhn.id_mohon) ide,
add_months(Last_day(sysdate)+1,-10) datejan,
add_months(Last_day(sysdate)+0,-2) onemonthbeforenow,
ku.nama u4
from
mohon mhn, kod_urusan ku, kod_caw kc
where
 mhn.kod_urusan = ku.kod(+)
and mhn.kod_caw = kc.kod(+)
AND KU.AKTIF = 'Y'
AND KU.KOD_JABATAN= 2
and mhn.trh_masuk between add_months(Last_day(sysdate)+1,-10) and add_months(Last_day(sysdate)+0,-2)
and (mhn.kod_caw = :p_kod_caw or :p_kod_caw is null)
and (mhn.kod_urusan in ('PBMT','PBMMK'))    
group by ku.nama

有人对这个解决方案的其他公式有任何想法吗?

1 个答案:

答案 0 :(得分:3)

试试这个,

AND mhn.trh_masuk BETWEEN trunc(SYSDATE,'YEAR') AND last_day(add_months(TRUNC(SYSDATE), -1)) + .99999