Back to Browse

SQL Interview Question: Month-over-Month Sales Growth with LAG() window function

141 views
Sep 18, 2025
6:34

SQL Interview Question: Month-over-Month Sales Growth with LAG() In this video, you’ll learn how to calculate month-over-month sales growth using the LAG() window function in SQL. This is one of the most frequently asked SQL interview questions for Data Analyst, Data Engineer, and BI roles. 👉 What you’ll learn: What is the LAG() function in SQL? How to compare current month sales with the previous month’s sales. How to calculate growth/difference between months. Step-by-step explanation with query and output. Real-time use cases in reporting and dashboards. 🧑‍💻 Sample Query Covered SELECT sales_month, sales, LAG(sales) OVER (ORDER BY sales_month) AS prev_month_sales, sales - LAG(sales) OVER (ORDER BY sales_month) AS growth FROM monthly_sales; 🔹 Perfect for SQL practice, interview preparation, and real-time projects. 📌 Don’t forget to like, share, and subscribe if you find this helpful! CREATE TABLE monthly_sales ( id INT PRIMARY KEY, sales_month DATE, sales INT ); INSERT INTO monthly_sales (id, sales_month, sales) VALUES (1, '2025-01-01', 1000), (2, '2025-02-01', 1200), (3, '2025-03-01', 1100), (4, '2025-04-01', 1300), (5, '2025-05-01', 1250), (6, '2025-06-01', 1400), (7, '2025-07-01', 1350), (8, '2025-08-01', 1500), (9, '2025-09-01', 1450), (10, '2025-10-01', 1600), (11, '2025-11-01', 1550), (12, '2025-12-01', 1700); ➤Python Full Course in Telugu: https://www.youtube.com/playlist?list=PLGxYVGJtIgoRhVcVF0JMbUfhQhvIrDXDW ➤SQL Tutorials in Telugu: https://www.youtube.com/playlist?list=PLGxYVGJtIgoSp_t2XW7Gsy_lrclFbMfdl ➤ Power BI DAX Tutorials in Telugu: https://www.youtube.com/playlist?list=PLGxYVGJtIgoS9D01gMmMKUaJ8lOetZtIr ➤ Join our Facebook group: https://www.facebook.com/groups/206746378741662 ➤ Join our WhatsApp group: https://chat.whatsapp.com/JXrRh9IX0GuC4xZgEovbuu Subscribe Now and Stay Updated! 🔔 ► Contact: +91-8142550075 ➤SQL Tutorials in Telugu: https://www.youtube.com/playlist?list=PLGxYVGJtIgoSp_t2XW7Gsy_lrclFbMfdl ➤ Power BI DAX Tutorials in Telugu: https://www.youtube.com/playlist?list=PLGxYVGJtIgoS9D01gMmMKUaJ8lOetZtIr ➤ Join our Facebook group: https://www.facebook.com/groups/206746378741662 ➤ Join our WhatsApp group: https://chat.whatsapp.com/JXrRh9IX0GuC4xZgEovbuu Subscribe Now and Stay Updated! 🔔 ► Contact: +91-8142550075

Download

0 formats

No download links available.

SQL Interview Question: Month-over-Month Sales Growth with LAG() window function | NatokHD