为了选择两个月之间的生日,其中FROMDATE和TODATE是预准备语句中的一些参数,我得出这样的结果:
select p.id as person_id, ... ... where e.active = 1 and extract(month from TODATE) >= extract(month from e.dateOfBirth) and extract(month from e.dateOfBirth) >= extract(month from FROMDATE) order by extract(month from e.dateOfBirth) DESC, extract(day from e.dateOfBirth) DESC
如何将其改进以适应几天的工作呢?
最后,我们选择了不同的解决方案,并在其中添加了拳头以创建周年纪念日:
where ... and (to_char(sysdate,'yyyy') - to_char(e.dateofbirth,'yyyy')) > 0 and add_months(e.dateofbirth, (to_char(sysdate,'yyyy') - to_char(e.dateofbirth,'yyyy')) * 12) >:fromDate: and :toDate: > add_months(e.dateofbirth, (to_char(sysdate,'yyyy') - to_char(e.dateofbirth,'yyyy')) * 12) order by extract(month from e.dateofbirth) DESC, extract(day from e.dateofbirth) DESC)