2017-05-10 61 views
0

我想達到以下,但面對像爲了解析函數的錯誤不允許在WHERE子句爲了分析功能在where子句

select a.araccno,a.ARBDTE, 
sum(aramt) over(partition by araccno,ARBDTE ORDER BY ARAMT asc) sum1 
,sum(b.Bill_Stmt_Discount_Amt) over(partition by b.bill_statement_id order by b.Bill_Stmt_Discount_Amt asc) sum2 
from stg.ars_etl a 
left outer join tgt.bill_sta_dis b 
on 'LL'||a.araccno||a.arbdte=b.bill_statement_id 
where sum1<> sum2 

我怎麼能在Teradata數據實現這個不準?

非常感謝!

回答

3

在大多數數據庫中,您可以使用子查詢或CTE。 Teradata有qualify條款:

select a.araccno, a.ARBDTE, 
     sum(aramt) over(partition by araccno,ARBDTE ORDER BY ARAMT asc) as sum1, 
     sum(b.Bill_Stmt_Discount_Amt) over (partition by b.bill_statement_id order by b.Bill_Stmt_Discount_Amt asc) as sum2 
from stg.ars_etl a left outer join 
    tgt.bill_sta_dis b 
    on 'LL'||a.araccno||a.arbdte = b.bill_statement_id 
qualify sum1 <> sum2; 
+0

太棒了!感謝戈登! – user3901666