/*****************************************************************/
/* Compare a row to a previous row...                            */
/* i.e. Find all payments that are greater than previous payment */
/*****************************************************************/

select * from payment
order by pay_date;


/* MySQL */

SELECT prev.payment_num, prev.amount as prev_amt, prev.pay_date as prev_date,
       curr.payment_num, curr.amount as curr_amt, curr.pay_date as curr_date
FROM payment prev JOIN payment curr
     ON curr.pay_date = TIMESTAMPADD(day,1,prev.pay_date)
WHERE curr.amount > prev.amount;


/* Oracle */

SELECT prev.payment_num, prev.amount as prev_amt, prev.pay_date as prev_date,
       curr.payment_num, curr.amount as curr_amt, curr.pay_date as curr_date
FROM payment prev JOIN payment curr
     ON curr.pay_date = prev.pay_date + 1
WHERE curr.amount > prev.amount;