我正在尝试实现以下但面临错误,例如在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中实现这一目标?
非常感谢!!
答案 0 :(得分:5)
在大多数数据库中,您将使用子查询或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;