Am trying to learn the Pattern matching that was introduced with Oracle 12c. However getting the ORA-00918: column ambiguously defined with from the below code. Am not sure where i missed it
SELECT CUSTOMER_ID,ORDER_TOTAL,ORDER_TIMESTAMP FROM DEMO_ORDERS MATCH_RECOGNIZE(
PARTITION BY CUSTOMER_ID
ORDER BY CUSTOMER_ID,ORDER_TIMESTAMP
MEASURES
A.CUSTOMER_ID AS CUSTOMER,
A.ORDER_TOTAL AS TOTAL_AMT,
A.ORDER_TIMESTAMP AS WHEN_HPA
ALL ROWS PER MATCH
PATTERN( A B* )
DEFINE
B AS (B.ORDER_TOTAL < PREV(B.ORDER_TOTAL))
)
The problem is your order by
clause; it seems to be seeing the original table column customer_id
and the match partition value at the same time.
But a you're partitioning by customer_id
, so ordering by that doesn't make any sense anyway. The ordering applies within the partition (as in analytic functions). So you can just remove that:
SELECT CUSTOMER_ID,ORDER_TOTAL,ORDER_TIMESTAMP FROM DEMO_ORDERS MATCH_RECOGNIZE(
PARTITION BY CUSTOMER_ID
ORDER BY ORDER_TIMESTAMP
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.