Menu
easyLotus's · window

Show each customer's previous purchase amount

A purchases table logs every member's transactions. For a loyalty report, CRM wants each purchase shown next to that same member's previous purchase amount, so they can flag anyone whose latest spend dropped sharply.

Return member_id, purchase_date, amount and prev_amount (the member's immediately preceding purchase amount, or NULL if it was their first), ordered by member_id then purchase_date.

Schema

purchases
purchase_idINT
member_idTEXT
purchase_dateDATE
amountNUMERIC

Example input

purchases
↑ Read the question

Keep going

Company names are trademarks of their respective owners, used here only to describe practice material. mahir_data is not affiliated with, endorsed by, or sponsored by any company named on this site. Terms.