回答

收藏

上个月的Oracle日期函数

技术问答 技术问答 240 人阅读 | 0 人回复 | 2023-09-14

我在下面的日期有硬编码的查询。我的目标是删除已编码的日期;该查询在运行时应提取上个月的数据。
: J! g$ t9 l+ G, h! |& Pselect count(distinct switch_id)
+ @  T. I0 H; P) v& v% P  w  from xx_new.xx_cti_call_details@appsread.prd.com8 ^& W$ h# M' O
where dealer_name =  'XXXX'
! y( W3 P/ m0 Y+ {- D' a/ {# F. J' f   and TRUNC(CREATION_DATE) BETWEEN '01-AUG-2012' AND '31-AUG-2012': i  G. z+ P2 K: l- o
我应该sysdate-15为此使用函数吗?: @! D' d# G+ G+ X
               
; W* R! Y! `! a5 D1 l+ z6 [. ]解决方案:
: o0 Q( n* \4 Z7 x                * L3 m1 `( e# R: v% ]7 Z4 ]: ?7 }" @  l
+ `3 z4 A- w! u5 u+ t
( I: }1 J" d/ M: N) e" d
                稍微修改Ben的查询,5 B* e0 U& n7 G/ w9 @6 G' e5 W
select count(distinct switch_id)   
! c3 ?2 L. m; V  from xx_new.xx_cti_call_details@appsread.prd.com  2 @9 F0 x" s6 v3 N; ^4 |- \
where dealer_name =  'XXXX'   
7 L0 ^4 H" Z3 N3 ], T1 X: q   and creation_date between add_months(trunc(sysdate,'mm'),-1) and last_day(add_months(trunc(sysdate,'mm'),-1))
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则