怎么在数据库中选择每月固定时间点的数据?请高手指点,谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/02 14:14:51
怎么在数据库中选择每月固定时间点的数据?比如每月25号的,也就是从上个月25号的到本月25号的,我的数据表中有时间字段.请高手指点,谢谢

SQL:where day(字段名)='25'
事情就是这样~~~~~~

where month(字段名)-month(字段名)='1' and 31-day(字段)<25

如果你想取每月25号的数据:
select * from your_table
where to_char(date_column ,'dd') = '25'

如果你想取上个月25号的到本月25号的数据:
select * from your_table
where date_column between add_months(to_date(to_char(date_column,'yyyymm')||25,'yyyymmdd'),-1) and to_date(to_char(date_column,'yyyymm')||25,'yyyymmdd')
真费劲~