我在下面的日期有硬编码的查询。我的目标是删除已编码的日期;该查询在运行时应提取上个月的数据。, I. k) _' p2 P; @
select count(distinct switch_id)9 J2 I, M! C4 ]5 `6 L/ s
from xx_new.xx_cti_call_details@appsread.prd.com% a* y: {( Y8 a, E3 J P8 }
where dealer_name = 'XXXX'* x5 v: E% f. d. J+ M1 v* c
and TRUNC(CREATION_DATE) BETWEEN '01-AUG-2012' AND '31-AUG-2012'0 \/ b( o- E2 Q5 P+ m
我应该sysdate-15为此使用函数吗? 3 N/ M: E8 h+ T6 G! y 0 E* [% T1 f' L& u7 ]% s1 L E 解决方案: ) ~* L( z5 K4 {' i* v+ x5 C 6 X! X) ?' c% b( n, t' @ O$ w
" N) h& I" a. f( a' o : J) _/ a2 P- D* T; h- T# y7 f 稍微修改Ben的查询, " Q6 ]( h( G. O( O6 A4 r! `7 |" G select count(distinct switch_id) # I' F. X i+ g8 c5 @) }
from xx_new.xx_cti_call_details@appsread.prd.com 3 r+ _' m& d7 E! x; l+ I& V where dealer_name = 'XXXX' " U9 T: q# N9 m
and creation_date between add_months(trunc(sysdate,'mm'),-1) and last_day(add_months(trunc(sysdate,'mm'),-1))