look back in SQL

Assume your name is named tablename, you may try this query:

SELECT customer_key
FROM (
    SELECT customer_key, max(order_date) as max_date
    FROM tablename group by customer_key
) a
WHERE a.max_date < (sysdate - 60);

Leave a Comment