The AI-generated SQL – no one dares to say they fully “understand” it

First, look at the following SQL query, which aims to find credit card customers whose transaction amount has increased for three consecutive months:

WITH ranked AS (

SELECT customer_id, month, amount,

LAG(amount,1) OVER(PARTITION BY customer_id ORDER BY month) as prev_1,