Sql 返回日期在未来范围内的记录
我有以下疑问:-Sql 返回日期在未来范围内的记录,sql,oracle,Sql,Oracle,我有以下疑问:- select actual_ssd from tblsales 是否可以从tblsales返回记录,其中实际ssd动态提前2个月返回 因此,如果我今天运行查询,它将返回2018年5月1日至2018年5月31日之间的所有记录。如果我在2018年4月4日运行它,它将返回2018年6月1日到2018年6月30日之间的所有记录。使用trunc和算术 where actual_ssd >= trunc(sysdate,'mm')+interval '2' month and a
select actual_ssd
from tblsales
是否可以从tblsales
返回记录,其中实际ssd
动态提前2个月返回
因此,如果我今天运行查询,它将返回2018年5月1日至2018年5月31日之间的所有记录。如果我在2018年4月4日运行它,它将返回2018年6月1日到2018年6月30日之间的所有记录。使用
trunc
和算术
where actual_ssd >= trunc(sysdate,'mm')+interval '2' month
and actual_ssd < trunc(sysdate,'mm')+interval '3' month
其中实际值>=trunc(系统日期,'mm')+间隔'2'个月
和实际的_ssd
将trunc
与算术结合使用
where actual_ssd >= trunc(sysdate,'mm')+interval '2' month
and actual_ssd < trunc(sysdate,'mm')+interval '3' month
其中实际值>=trunc(系统日期,'mm')+间隔'2'个月
和实际的_ssd
当然可以
select *
from tblsales
where actual_ssd >= trunc(add_months(sysdate, 2), 'MM')
and actual_ssd < trunc(add_months(sysdate, 3), 'MM')
选择*
来自TBL销售
其中,实际\u ssd>=trunc(添加\u个月(sysdate,2),“MM”)
和实际月数
trunc()
根据格式掩码,对日期值执行向下舍入;使用'MM'
参数,它向下舍入到当前月份的第一个月add_months()
完全按照您认为的那样,在date参数中添加所需的月数。当然可以
select *
from tblsales
where actual_ssd >= trunc(add_months(sysdate, 2), 'MM')
and actual_ssd < trunc(add_months(sysdate, 3), 'MM')
选择*
来自TBL销售
其中,实际\u ssd>=trunc(添加\u个月(sysdate,2),“MM”)
和实际月数
trunc()
根据格式掩码,对日期值执行向下舍入;使用'MM'
参数,它向下舍入到当前月份的第一个月add_months()
完全按照您认为的那样,在date参数中添加所需的月数