我在下面的日期有硬编码的查询。我的目标是删除已编码的日期;该查询在运行时应提取上个月的数据。 2 o, h3 ~$ I, W9 v; R4 H& ^select count(distinct switch_id) ( s8 Y0 F! D! ~, h" q from xx_new.xx_cti_call_details@appsread.prd.com( n; _: e: }- A; E7 V: K
where dealer_name = 'XXXX'# s! C# B/ Q9 l P* T/ p+ D
and TRUNC(CREATION_DATE) BETWEEN '01-AUG-2012' AND '31-AUG-2012' 2 \4 {2 O) F0 y1 e% _我应该sysdate-15为此使用函数吗? 8 ~$ R G2 o, j2 m; y/ S& ^2 f : F4 F* P' b. d! J& q1 e8 q解决方案: $ i7 W' q) {( P/ t2 E ! E: W4 T2 w$ B Z Z7 J+ h
9 n+ H; L( J; N6 x+ u5 F
6 O* P5 @3 f6 o& j7 g6 R1 V, a* Y
稍微修改Ben的查询, Z' R: n; N' d' E
select count(distinct switch_id) k7 z, E) a8 \ U% `. J# z
from xx_new.xx_cti_call_details@appsread.prd.com + E8 P# i/ M, M8 t- A, }$ R where dealer_name = 'XXXX' ; D) M$ U2 k! S9 _: o
and creation_date between add_months(trunc(sysdate,'mm'),-1) and last_day(add_months(trunc(sysdate,'mm'),-1))