我在下面的日期有硬编码的查询。我的目标是删除已编码的日期;该查询在运行时应提取上个月的数据。2 i2 i4 i1 c8 ]8 I- \) v
select count(distinct switch_id): R8 c4 U* G5 a8 |; B
from xx_new.xx_cti_call_details@appsread.prd.com " S5 Z, F3 o( l o; F where dealer_name = 'XXXX'& h) m( ?5 d! S) z$ `
and TRUNC(CREATION_DATE) BETWEEN '01-AUG-2012' AND '31-AUG-2012' 7 ? d: D$ h& T1 N6 i7 I6 I) ~我应该sysdate-15为此使用函数吗?* R. X; A: C+ p, \+ Y. N
3 h. C' D# y D8 O/ I3 A 解决方案: $ M+ F- A. U2 s1 v' i: |' y: T4 s ! w, N. j' P0 q% q
5 _, S8 P! F: I* k2 [/ e7 d
3 x) D" G/ R' k* y 稍微修改Ben的查询,9 ?: i( F, z! M. K6 n
select count(distinct switch_id) ( \# v: ]* O0 ` from xx_new.xx_cti_call_details@appsread.prd.com 8 U* I4 i' G) `* z3 F& c% E where dealer_name = 'XXXX' 2 p, v3 _$ {* `! B' }3 M3 L Y and creation_date between add_months(trunc(sysdate,'mm'),-1) and last_day(add_months(trunc(sysdate,'mm'),-1))