Introduction
Sometimes we just want SQL to be a bit smarter. Maybe we need to figure out who’s performing best in a team, find someone’s very first sale, or compare today’s numbers with yesterday’s. We might want to group customers into spending tiers, spot sudden jumps or drops in sales, or keep a running total without writing complex loops. We could write long queries with subselects, joins, and temp tables… but there’s a much cleaner way.
The common thread in all these problems is that we are not just looking at one row — We looking at it in relation