2
我在将SQL语句从Oracle转换为Teradata时遇到问题。在Oracle的声明是这样的:“Teradata的第一个订单”
SELECT ar.account_no,
MAX (ah.bal_acct) KEEP (DENSE_RANK FIRST ORDER BY ah.created_t desc)
FROM ar
JOIN ah ON ah.obj_id0 = ar.poid_Id0
JOIN acc ON a.poid_id0 = ar.account_obj_Id0
WHERE acc.account_no = '1234'
AND ah.created_t <= 1434753495
GROUP BY ar.account_no
我需要在Teradata中做类似的声明。我试着用
QUALIFY ROW_NUMBER() OVER(PARTITION BY max(ah.bal_acct) ORDER BY ah.created_t desc) = 1
的东西,但是所有的时间我有错误:选择非集合值必须是关联组的一部分。
这是我得到:
Select ar.account_no, ah.created_t, ah.bal_acct
FROM VD_REPLICA_BRM.pi_tp_acct_ar_t ar
JOIN VD_REPLICA_BRM.pi_tp_acct_ar_hist_T ah ON ah.obj_id0 = ar.poid_Id0
JOIN VD_REPLICA_BRM.pi_account_t acc ON acc.poid_id0 = ar.account_obj_Id0
WHERE acc.account_no = '00003095660515'
AND ah.created_t <= CAST('2016-10-31' AS DATE FORMAT 'YYYY-MM-DD')
QUALIFY ROW_NUMBER() OVER(PARTITION BY max(ah.bal_acct) ORDER BY ah.created_t desc) = 1
GROUP BY ar.account_no
我在哪里都错了吗?
'ah.created_t <= date'2016-10-31''。这是日期文字的ANSI/ISO符号 –