Skip to content
Advertisement

Joining on the same key on the next row

Suppose we have a table which contains customer_id, order_date, and ship_date. A reorder of the product occurs when the same customer’s next order_date is within 30 days of the last ship_date.

Requested: Reorders

How can I retrieve only the records for the same customers who had reorders, next order_date within 30 days of the last ship_date.

Advertisement

Answer

You can use exists as follows:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement